Explore Library
QuizAdvanced

DI Lifetimes in Middleware

Learn which service lifetime to inject into a middleware constructor in ASP.NET Core.

In ASP.NET Core, a custom middleware class is instantiated once for the application's lifetime. If you inject a service via the middleware's constructor, which service lifetime is safe to use there?