Replies: 1 comment 1 reply
-
Did you figure out how this would actually work? The difficulty is that the middleware order is important but often service registration order is not (if you're not adding multiple implementations). On top of that, the DI container can't be mutated after its created (that's by design). This leads to this 2-phase model that has been with ASP.NET Core for the last 10 years. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is more of a rough idea rather than an API proposal so I opened up this for a discussion.
More often than not middlewares, endpoints have some services that need to be registered.
If you want to disable a middleware you most likely skip service registration as well. If you only add the middleware it's just an invalid usage. While the opposite is ok but you usually want these in sync.
The proposal here is to unify these two phases and allow services to be added alongside of middlewares at any point so only calling UseHttpLogging would be sufficient.
This way endpoints and their corresponding services can be configured in the same place to avoid misusage and providing more control to the extension on how these should match.
With this underlying API in place, it would be possible to mix service, middleware registration at any point in the pipeline but I don't see this as a downside since you would likely want to bring service registration (setup) closer to it's middleware (usage) and there would a single place to pass any options needed.
Beta Was this translation helpful? Give feedback.
All reactions