-
Notifications
You must be signed in to change notification settings - Fork 5k
Add class-based host configurators or service collection modules #36509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
This issue will now be closed since it had been marked |
Is your feature request related to a problem?
Host builder configurations in projects with too many services / special case configurations (e.g. depending on the current host environment etc.) become bloated and unreadable quite fast.
Describe the solution you'd like
Either an interface which allows to provide host configurations through separate types (
IConfigureWebHostBuilder
) or at least a module feature forIServiceCollection
(IServiceModule
).Detailed description
The current
IWebHostBuilder
contract only allows configuring the web host through fluent-style configuration delegates (usually in the form ofAction<WebHostBuilderContext, TSomeBuilder>
). This fluent approach is very nice for small projects or when using aggregating helper extension methods (such asCreateDefaultBuilder
), but when numerous frameworks and services are involved, that might also need to be configured depending on the environment (dev, prod), the composition root becomes quite bloated, mixed with all kinds of configurations, constants, verbose registration code etc.A nice way to clean the configuration up a bit in such a case would be configuration classes, similiar to Autofac's Module feature. What I would imagine is a small interface called
IConfigureWebHostBuilder
, which has a singleConfigure()
method that passes either the currentIWebHostBuilder
instance, or a generic variant which passes theWebHostBuilderContext
and an associated builder (IServiceCollection
,IConfigurationBuilder
). TheIWebHostBuilder
interface would then have an additional methodUseConfigurator
, for example. The webhost builder would then either instantiate the classes, or, if an instance is already provided, pass itself to it. Nothing much else.That way, developers could separate many configuration concerns from each other and reduce the complexity of the configuration code.
Variant 1
Variant 2
Variant 3
The text was updated successfully, but these errors were encountered: