-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Allow IHostBuilder to have the convenient UseStartup<> pattern that IWebHostBuilder implements #42258
Comments
+1 See also this thread on Startup.cs in a self-hosted .NET Core Console Application for a large number of use cases that would get value out of using the DI framework with the separation of concerns that comes from the |
|
@BrennanConroy , not sure I understand why |
I have to agree with @KyleMit here. This pattern has numerous use cases beyond web apps, and expanding it to other types of Core applications could help simplify and standardize service/environment configuration. The only part of it that seems "web app specific" to me would be configuration of the HTTP request pipeline, but even that has uses outside of web apps. @BrennanConroy, please open this back up. Web Apps don't have a monopoly on starting up. |
I'd mainly be concerned about confusing it with existing web app Startup patterns. Let me start with some background. Startup originated back with Microsoft.Owin and only had a Configure method for setting up an http request pipeline. AspNetCore expanded on that to add ConfigureServices for setting up DI, but the http pipeline was still the primary focus. With IHostBuilder, ConfigureServices has moved directly to to the host builder and Configure moved to a web app specific area. The web app specific area maintained the Startup pattern for backwards compatibility, but now it's only a bridged over these two new locations. Note when we moved from WebHostBuilder to HostBuilder we lost the ability to DI inject services into the Startup class, except for a few core services provided by the HostBuilder directly. The signatures allowed for ConfigureServices also became more constrained. The ask here is to replicate the Startup pattern for IHostBuilder, but with only a ConfigureServices method. The relevant questions are why and how? Why?To separate app bootstraping logic from the services logic. I can appreciate the appeal of Startup as an organizational pattern. To inject services into Startup. This one doesn't work anymore, the only things you can inject are items from the HostBuilderContext, and you already have access to those from IHostBuilder.ConfigureServices. How?Adding Writing code like this: Adding |
Tagging subscribers to this area: @eerhardt, @maryamariyan |
Since this is a proposal for adding API, is someone willing make the proposal in the format of the template linked in step 1 of https://github.com/dotnet/runtime/blob/master/docs/project/api-review-process.md ? |
Thanks @Tratcher for the thoughtful response and proposal. This solution seems adequate to me @eerhardt I gave the template a shot #42364 |
Closing this issue in favor of #42364. |
Preamble
I would like to see a way to use the convenient
Startup.cs
pattern thatIWebHostBuilder
has implemented, but at theIHostBuilder
level.I don't like working in the
Program.cs
file... That is typically for boiler-plate code to start a host. Now I find myself in there constantly making changes just to work on my DI pipeline, for example:Program.cs:
I'd like to see...
It would be really convenient to segregate the boiler-plate code from the DI injection routines. So instead of the code above, do this:
Additional context
I put together an extension that makes this possible, but I am not 100% sure this is proper. Maybe there is a better way you folks can come up with that would accomplish this in a more organic manner:
Thank you for taking the time to look at this request.
The text was updated successfully, but these errors were encountered: