On creating Startup, custom services do not resolves
See original GitHub issueDescribe the bug
I have a library for strongly typed IConfiguration wrapper, it works fine on 2.2, but in 3.0.0 GenericWebHostBuilder.UseStartup
does not resolve custom services, already added to IServiceCollection
to HostBuilder
/WebHostBuilder
at the moment Startup
created using ActivatorUtilities
.
For now used GenericWebHostBuilder.HostServiceProvider
. It can resolve only IHostingEnvironment
and IConfiguration
.
To Reproduce
Complete example: https://github.com/phema-team/Phema.Configuration/tree/master/examples/Phema.Configuration.Example Steps to reproduce the behavior:
- Use
builder.ConfigureServices((c, s) => s.AddSomeService())
- Use
builder.ConfigureWebHostDefaults
(callbuilder.ConfigureWebHost
) and addStartup
- In
Startup
addSomeService
to constructor
Expected behavior
All services added previously to IServiceCollection
can be resolved in Startup creation
Screenshots
Additional context
I think we should use in GenericWebHostBuilder.UseStartup
for creating Startup
all previously registered services passing IServiceProvider
built from IServiceCollection
parameter to GenericWebHostBuilder.HostServiceProvider
. Logic the same, if IHostingEnvironment
/IConfiguration
resolve from WebHostBuilderContext
, else try to resolve from already added services
I added pull request with potential fix https://github.com/aspnet/AspNetCore/pull/9296
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
And the official announcement: https://github.com/aspnet/Announcements/issues/353
This issue is closed, please follow the announcement issue instead.