예제 #1
0
 //demo transient, scoped
 public IActionResult DemoTransient()
 {
     ViewBag.Service1 = _services1.GetID();
     ViewBag.Service2 = _services2.GetID();
     ViewBag.Service3 = _services3.GetID();
     ViewBag.Service4 = _services4.GetID();
     ViewBag.Service5 = _services5.GetID();
     return(View());
 }
 public IActionResult DemoTransient()
 {
     ViewBag.Service1 = _sv1.GetID();
     ViewBag.Service2 = _sv2.GetID();
     ViewBag.Service3 = _sv3.GetID();
     ViewBag.Service4 = _sv4.GetID();
     ViewBag.Service5 = _sv5.GetID();
     ViewBag.Service6 = _sv6.GetID();
     return(View());
 }
예제 #3
0
        public IActionResult Index()
        {
            var model = new HomeViewModel()
            {
                TransientOne = transitentOne.GetID(), TransientTwo = transientTwo.GetID(),
                ScopedOne    = scopedOne.GetID(), ScopedTwo = scopedTwo.GetID(),
                SingletonOne = singletonOne.GetID(), SingletonTwo = singletonTwo.GetID()
            };

            return(View(model));
        }
예제 #4
0
        public IActionResult DemoTransient()
        {
            //var result = $"Service 1: {_service1.GetID()} - Service 2: {_service2.GetID()}";
            //return Content(result);

            ViewBag.Service1 = _service1.GetID();
            ViewBag.Service2 = _service2.GetID();
            ViewBag.Service3 = _service3.GetID();
            ViewBag.Service4 = _service4.GetID();
            ViewBag.Service5 = _service5.GetID();
            return(View());
        }
        public IActionResult Index()
        {
            var guid1 = _transientService1.GetID().ToString();
            var guid2 = _transientService2.GetID().ToString();

            var guid3 = _scopedService1.GetID().ToString();
            var guid4 = _scopedService2.GetID().ToString();

            var guid5 = _singletonService1.GetID().ToString();
            var guid6 = _singletonService2.GetID().ToString();

            return(Ok());
        }
예제 #6
0
        public IActionResult Index()
        {
            ViewBag.message1 = "First Instance " + _transientService1.GetID().ToString();
            ViewBag.message2 = "Second Instance " + _transientService2.GetID().ToString();

            ViewBag.message3 = "First Instance " + _scopedService1.GetID().ToString();
            ViewBag.message4 = "Second Instance " + _scopedService2.GetID().ToString();

            ViewBag.message6 = "First Instance " + _singletonService1.GetID().ToString();
            ViewBag.message7 = "Second Instance " + _singletonService2.GetID().ToString();

            return(View());
        }
예제 #7
0
        public IActionResult Index()
        {
            var singleton1            = singletonService1.GetID();
            var singleton2            = singletonService2.GetID();
            var singletonValueIsEqual = singleton1 == singleton2;

            //Injecting service with different lifetimes into another

            /* When the request comes for the first time a new instance of the singleton is created.
             * It also creates a new instance of the transient object and injects into the Singleton service.
             *
             * When the second request arrives the instance of the singleton is reused.
             * The singleton already contains the instance of the transient service Hence it is not created again.
             * This effectively converts the transient service into the singleton */
            var innerServices = singletonService1.TransientService.GetID() == singletonService2.TransientService.GetID();

            var scoped1            = scopedService1.GetID();
            var scoped2            = scopedService2.GetID();
            var scopedValueIsEqual = scoped1 == scoped2;

            var transient1            = transientService1.GetID();
            var transient2            = transientService2.GetID();
            var transientValueIsEqual = transient1 == transient2;


            //set viewdatat values
            SetViewData("singletonService1", singleton1);
            SetViewData("singletonService2", singleton2);
            SetViewData("singleton_Inner_Transiet_Service1", singletonService1.TransientService.GetID());
            SetViewData("singleton_Inner_Transiet_Service2", singletonService2.TransientService.GetID());

            SetViewData("scopedService1", scoped1);
            SetViewData("scopedService2", scoped2);

            SetViewData("TransientService1", transient1);
            SetViewData("TransientService2", transient2);

            return(View());
        }
예제 #8
0
 public IActionResult Index()
 {
     ViewBag.Service5 = _services5.GetID();
     return(View());
 }