public async Task InvokeAsync(HttpContext context, TransientService transientService, ScopedService scopedService, SingletonService singletonService) { context.Items.Add("CustomMiddlewareTransient", $"Transient Middleware - {transientService.GetGuid()}"); context.Items.Add("CustomMiddlewareScoped", $"Scoped Middleware - {scopedService.GetGuid()}"); context.Items.Add("CustomMiddlewareSingleton", $"Singleton Middleware - {singletonService.GetGuid()}"); await _next(context); }
public IActionResult Index() { var messages = new List <String> { HttpContext.Items["CustomMiddlewareTransient"].ToString(), $"Transient Controller - {_transientService.GetGuid()}", HttpContext.Items["CustomMiddlewareScoped"].ToString(), $"Scoped Controller - {_scopedService.GetGuid()}", HttpContext.Items["CustomMiddlewareSingleton"].ToString(), $"Singleton Controller - {_singletonService.GetGuid()}", }; return(View(messages)); }