Skip to content

Improve HostBuilder and WebApplicationBuilder ServiceCollection integration #61635

@halter73

Description

@halter73

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions