-
Notifications
You must be signed in to change notification settings - Fork 310
Allow resolving Startup from external service provider #1309
Comments
Probable duplicate of #1060 |
@Tratcher No, it has nothing to do with collection |
As you can see on line 156 WebHostBuilder calls ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(serviceCollection) to get service provider. BuildServiceProvider simply creates new provider with no regards to configuration and registered factory: public static ServiceProvider BuildServiceProvider(this IServiceCollection services, ServiceProviderOptions options)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return new ServiceProvider(services, options);
} |
I come to the same conclusion as @ENikS and also tried to relay this to @davidfowl at some point, but i failed to create a repro/ convey the problem. |
I’m not clear on what’s being asked for here. The WebHostBuilder cannot function with just an already built IServiceProvider, it needs to be an IServiceCollection (which is the issue that @Tratcher linked) |
Ah I just read the other repository. You’re specifically talking about the hosting container itself (there’s always 2). Im not sure that’s possible with the way things are designed today. We would need to not DI activate the IServiceProviderFactory which it is today. I’m not sure this is doable without hacks or breaking changes but we’d be open to looking at pull requests. |
The solution is rather simple. Requires changing of 3 lines of code. Sent you a PR |
In #1060, @davidfowl you said "This isn't possible today. The To be clear, I want to replace the container that gets a I'm not advocating for this lambda-type approach specifically, but something along these lines: Is this chicken/egg impossible or just the interfaces/code in place won't allow it? Like is it worth expending the effort to try and build a PR/workaround for or is this truly a dead-end? I have a truly miserable workaround after like dozens of hours of pain involving registering the root container as a backup Autofac registration source and letting the |
When Unity container is configured to replace built in DI engine we discovered that it is not being used to create and resolve Startup class.
Currently WebHost builder is hard coded to create new built-in/internal service provider and resolve Startup class from that provider. Configured provider is ignored and created later. As result no types registered with Unity are available to the Startup constructor.
For more information please see this project
The text was updated successfully, but these errors were encountered: