-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom IServiceCollection in build method #44435
Comments
This isn't possible today. The WebHostBuilder is the root of the DI universe and you can't replace the built in |
@davidfowl I wonder if the IServiceCollection could be passed as a parameter in "Build" method of WebHostBuilder (as an optional parameter, btw), I think it would have a slight impact on what's running today. I just don't want to mimic the WebHost class just to be able to pass an existing service configuration. |
Allow to pass an existing IServiceCollection instance to WebHostBuilder which should be used instead of creating a new one inside WebHostBuilder. Could be a solution to issue #1060.
I would also love to have such an option. We also haven an existing bootstrapping project where we already create an IServiceCollection and currently its pretty hard to use the WebHostBuilder in that scenario. I made some hacks with IProviderFactory and stuff and it works. But it feels kinda hacky and official support for such a scenario would be very helpful. |
I would also love to have such an option. I want to use ILogger a few steps before building WebHostBuilder. It's quite logical, in my opinion, to configure IServiceCollection with ILogger, build services, get ILogger from it, execute initial steps (perhaps use ILogger instance), then pass that IServiceCollection or services or appendable DI configuration in any form to WebHostBuilder, knowing that services configured earlier in pipeline become configured in WebHost. |
Moving to runtime. We plan to obsolete WebHostBuilder so any feature work here would have to go into the generic HostBuilder. |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue meta data
|
This should be closed, I'm not exactly sure what a custom Build method would do here. We have an |
I didnt have tried the HostBuilder yet, but the problem here was not the extensibility from my point of view. The WebHostBuilder always builds its own ServiceCollection and allows other only to hook in. But what about scenarios where you already have another application root ServiceCollection and only want to add a webhost to it? |
HostBuilder has a similar problem but that's by design as a host is responsible for creating and managing the DI container and hosted services within that container. It sounds like you're looking for something else. What experience are you looking for? |
We have an company intern boostrap system for services/docker and co, witch builds upon everything we need for all off our services. This works also with ServiceCollection but it creates one already at start time. We want to use HTTP/ASP.NET as opt in feature to it. So manly wee need the setup part from WebHostBuilder to work against and existing ServiceCollection. I mad it work by using forwarding IServiceProvider. But its complicated and feels messy while all it would nee is that WebHostBuilder would add a Ctor witch accepts an ServiceCollection. |
Maybe you should target the the FWIW, I think it would be possible to take an initial |
I will try to revisit that and build an example. But it could take a little while right now. |
This issue is 4 years old, I got time 😆 |
|
Is that possible to pass a custom IServiceCollection instead of using the internal IServiceCollection created in Build method?
My case is that the WebHostBuilder is just part of a bigger application (which contains part of code running as a service, for example)
Because the services are registered by an external IServiceCollection, it would be impossible to utilize the existing IServiceProvider without duplicating registrations (or delegating them to existing IServiceProvider).
The text was updated successfully, but these errors were encountered: