✅ Factory-based middleware activation in asp.net core

this part of the docs says that Factory-based middleware is activated per request while when i register this middleware in app service container it is registered as a transient or scoped , this part confuse me is it registered twice
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/extensibility?view=aspnetcore-8.0
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 middleware
UseMiddleware 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.
Learn how to use strongly-typed middleware with a factory-based activation implementation in ASP.NET Core.
Was this page helpful?