ASP.NET Core 2.1 now supports Generic Host, and is there a way to share DI container registered in IWebHostBuilder among GenericHosts/HostBuilders?
Even if you could there are some core services that would break. E.g. IApplicationLifetime is assumed to be a singleton per host.
No you cannot. Why are you using both in the same process?
I have an API running under WebHost and a stream process running under GenericHost. The problem is when in my service orchestrator persists to a database under DI of WebHost and after that, I send a message to the streamer under GenericHost. Looks like (and really is) my IHost tries to resolve the service dependencies there were already resolved by WebHost. I don't want to duplicate my dependencies.
Actually, I'm thinking to migrate everything to GenericHost (even my web api), so all components will be under the same container.
Any suggestions?
We don't plan to get eveything migrated to GenericHost until at least 3.0, though here's an initial sample of that may look like: https://github.com/aspnet/Hosting/blob/8d55a447d480bb826cf0088718bbea200b2537bb/samples/GenericWebHost/Program.cs
If you're in the same process you should just do everything in the web host. What @Tratcher brought up is what we plan to investigate in 3.0
@davidfowl you mean, run everything under GenericHost or WebHost?
WebHost
@Tratcher is the example just a concept, or should create a response when running?
It doesn't hook up a real server due to some circular dependency issues, but you should be able to add Kestrel for some one-off testing. See https://github.com/aspnet/KestrelHttpServer/issues/2498