Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.AspNetCore.Mvc;
- namespace Arshinov.WebApp.Controllers
- {
- public interface ISingletonObj
- {
- }
- public class SingletonObj : ISingletonObj
- {
- public override string ToString()
- {
- return "Singleton";
- }
- }
- public interface ITransientObj
- {
- }
- public class TransientObj : ITransientObj
- {
- private readonly ISingletonObj _singletonObj;
- public TransientObj(ISingletonObj singletonObj)
- {
- _singletonObj = singletonObj;
- }
- public override string ToString()
- {
- return "Transient";
- }
- }
- public interface IScopedObj
- {
- }
- public class ScopedObj : IScopedObj
- {
- private readonly ISingletonObj _singletonObj;
- public ScopedObj(ISingletonObj singletonObj)
- {
- _singletonObj = singletonObj;
- }
- public override string ToString()
- {
- return "Scoped";
- }
- }
- public class NewController : Controller
- {
- private readonly IScopedObj _scopedObj;
- private readonly ISingletonObj _singletonObj;
- private readonly ITransientObj _transientObj;
- public NewController(IScopedObj scopedObj, ISingletonObj singletonObj, ITransientObj transientObj)
- {
- _scopedObj = scopedObj;
- _singletonObj = singletonObj;
- _transientObj = transientObj;
- }
- // GET
- public IActionResult Index()
- {
- return Ok(_transientObj + " " + _singletonObj + " " + _scopedObj);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement