Not all default services are added to WebApplicationBuilder.Services
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
HostBuilder adds some default services in [CreateServiceProvider()](https://github.com/dotnet/runtime/blob/e983168f871dcba090ff6ec08c0d2c7d4353fb8e/src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs#L238-L260) that are not added to WebApplicationBuilder.Services until after build.
```csharp
var builder = WebApplication.CreateBuilder();
// System.InvalidOperationException: No service for type IHost has been registered.
builder.Services.BuildServiceProvider().GetRequiredService();
```
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.
Contributor guide
Assessment
This issue has not been assessed yet.