Skip to content

Not all default services are added to WebApplicationBuilder.Services #34825

@halter73

Description

@halter73

HostBuilder adds some default services in CreateServiceProvider() that are not added to WebApplicationBuilder.Services until after build.

var builder = WebApplication.CreateBuilder();
// System.InvalidOperationException: No service for type IHost has been registered.
builder.Services.BuildServiceProvider().GetRequiredService<IHost>(); 

Before #34455 was merged, these services never showed up in WebApplicationBuilder.Services even after build. Because CreateServiceProvider() is called in HostBuilder.Build(), we cannot access these service descriptors any earlier without new public API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3Work that is nice to havearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-hosting

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions