IMiddlewareFactory/IMiddleware is an extensibility point for middleware activation that offers the following benefits:Activation per client request (injection of scoped services)Strong typing of middlewareUseMiddleware extension methods check if a middleware's registered type implements IMiddleware. If it does, the IMiddlewareFactory instance registered in the container is used to resolve the IMiddleware implementation instead of using the convention-based middleware activation logic. The middleware is registered as a scoped or transient service in the app's service container.IMiddleware is activated per client request (connection), so scoped services can be injected into the middleware's constructor.
IMiddlewareFactory/IMiddleware is an extensibility point for middleware activation that offers the following benefits:Activation per client request (injection of scoped services)Strong typing of middlewareUseMiddleware extension methods check if a middleware's registered type implements IMiddleware. If it does, the IMiddlewareFactory instance registered in the container is used to resolve the IMiddleware implementation instead of using the convention-based middleware activation logic. The middleware is registered as a scoped or transient service in the app's service container.IMiddleware is activated per client request (connection), so scoped services can be injected into the middleware's constructor.