Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using Microsoft.AspNetCore.Mvc;
  3.  
  4. namespace Arshinov.WebApp.Controllers
  5. {
  6.     public interface ISingletonObj
  7.     {
  8.     }
  9.  
  10.     public class SingletonObj : ISingletonObj
  11.     {
  12.         public override string ToString()
  13.         {
  14.             return "Singleton";
  15.         }
  16.     }
  17.  
  18.     public interface ITransientObj
  19.     {
  20.     }
  21.  
  22.     public class TransientObj : ITransientObj
  23.     {
  24.         private readonly ISingletonObj _singletonObj;
  25.  
  26.         public TransientObj(ISingletonObj singletonObj)
  27.         {
  28.             _singletonObj = singletonObj;
  29.         }
  30.  
  31.         public override string ToString()
  32.         {
  33.             return "Transient";
  34.         }
  35.     }
  36.  
  37.     public interface IScopedObj
  38.     {
  39.     }
  40.  
  41.     public class ScopedObj : IScopedObj
  42.     {
  43.         private readonly ISingletonObj _singletonObj;
  44.  
  45.         public ScopedObj(ISingletonObj singletonObj)
  46.         {
  47.             _singletonObj = singletonObj;
  48.         }
  49.  
  50.         public override string ToString()
  51.         {
  52.             return "Scoped";
  53.         }
  54.     }
  55.  
  56.     public class NewController : Controller
  57.     {
  58.         private readonly IScopedObj _scopedObj;
  59.         private readonly ISingletonObj _singletonObj;
  60.         private readonly ITransientObj _transientObj;
  61.  
  62.         public NewController(IScopedObj scopedObj, ISingletonObj singletonObj, ITransientObj transientObj)
  63.         {
  64.             _scopedObj = scopedObj;
  65.             _singletonObj = singletonObj;
  66.             _transientObj = transientObj;
  67.         }
  68.  
  69.         // GET
  70.         public IActionResult Index()
  71.         {
  72.             return Ok(_transientObj + " " + _singletonObj + " " + _scopedObj);
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement