Skip to content
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

Improve HostBuilder and WebApplicationBuilder ServiceCollection integration #61635

Closed
halter73 opened this issue Nov 15, 2021 · 3 comments
Closed
Assignees
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-Hosting
Milestone

Comments

@halter73
Copy link
Member

halter73 commented Nov 15, 2021

Today WebApplicationBuilder has some hacky logic to synchronize the WebApplicationBuilder.Services IServiceCollection and the HostBuilder's IServiceCollection in case any custom services have been added via HostFactoryResolver. This logic can be found here.

The synchronization is not perfect and can lead to bugs like the following throwing even though the equivalent would work in Startup.ConfigureServices when using the HostBuilder directly.

builder.Services.BuildServiceProvider().GetRequiredService<IHostApplicationLifetime>();

We should look into adding an API to HostBuilder to share an IServiceCollection with the WebApplicationBuilder.

Related: #61634

@halter73 halter73 added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-Hosting labels Nov 15, 2021
@ghost
Copy link

ghost commented Nov 15, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Today WebApplicationBuilder has some hacky logic to synchronize the WebApplicationBuilder.Services IServiceCollection and the HostBuilder's IServiceCollection in case any custom services have been added via HostFactoryResolver. This logic can be found here.

The synchronization is not perfect and can lead to bugs like the following throwing even though it would work in Startup.ConfigureServices when using the HostBuilder directly.

builder.Services.BuildServiceProvider().GetRequiredService<IHostApplicationLifetime>();

We should look into adding an API to HostBuilder to share an IServiceCollection with the WebApplicationBuilder.

Related: #61634

Author: halter73
Assignees: -
Labels:

api-suggestion, area-Extensions-Hosting

Milestone: -

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Nov 15, 2021
@maryamariyan maryamariyan removed the untriaged New issue has not been triaged by the area owner label Nov 15, 2021
@maryamariyan maryamariyan added this to the 7.0.0 milestone Nov 15, 2021
@eerhardt
Copy link
Member

eerhardt commented Jan 4, 2022

@halter73 - Do you have an idea of what the API would look like? Can you update the issue to use the API proposal template?

https://github.com/dotnet/runtime/issues/new?assignees=&labels=api-suggestion&template=02_api_proposal.yml&title=%5BAPI+Proposal%5D%3A+

@halter73
Copy link
Member Author

halter73 commented Feb 1, 2022

This should be addressed by the API proposed in #61634.

@halter73 halter73 closed this as completed Feb 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-Extensions-Hosting
Projects
None yet
Development

No branches or pull requests

3 participants