Beispiel #1
0
 public HomeController(ILogger <HomeController> logger, SingletonGuidService singleton, ScopedGuidService scoped, TransientGuidService transient)
 {
     _logger       = logger;
     singletonGUID = singleton;
     scopedGUID    = scoped;
     transientGUID = transient;
 }
Beispiel #2
0
 public HomeController(ILogger <HomeController> logger,
                       SingletonGuidService singleton,
                       ScopedGuidService scoped,
                       TransientGuidService transient) // constructor injection
 {
     _logger    = logger;
     _singleton = singleton;
     _scoped    = scoped;
     _transient = transient;
 }
Beispiel #3
0
        public IActionResult Index([FromServices] SingletonGuidService singleton, [FromServices] ScopedGuidService scoped, [FromServices] TransientGuidService transient)
        {
            /*
             * ViewData["singleton"] = singletonGUID;
             * ViewData["scoped"] = scopedGUID;
             * ViewData["transient"] = transientGUID;
             */
            TempData.Clear();

            return(View());
        }
Beispiel #4
0
        // we can do DI to individual action methods
        // (if it's expensive to initialize that service, and only one aciton method needs)
        public IActionResult Index([FromServices] SingletonGuidService singleton,
                                   [FromServices] ScopedGuidService scoped,
                                   [FromServices] TransientGuidService transient)
        {
            // ViewData and friends
            // sometimes, it's not worth it to try and fit every piece of data the view needs into
            // the model / viewmodel.

            // ViewData is basically a dictionary of string to object.
            ViewData["singleton"] = _singleton;
            ViewData["scoped"]    = _scoped;
            ViewData["transient"] = _transient;

            ViewData["singleton2"] = singleton;
            ViewData["scoped2"]    = scoped;
            ViewData["transient2"] = transient;

            return(View());
        }