aspnet / Hosting

[Archived] Code for hosting and starting up an ASP.NET Core application. Project moved to https://github.com/aspnet/Extensions and https://github.com/aspnet/AspNetCore
Apache License 2.0
552 stars 312 forks source link

Feature gaps to make replace WebHostBuilder with HostBuilder #1544

Closed davidfowl closed 5 years ago

davidfowl commented 6 years ago

Some notes:

Inventory of extension methods on IWebHostBuilder:

3rd Party

Github Search https://github.com/search?l=C%23&p=4&q=IWebHostBuilder&type=Code

tidyui commented 5 years ago

Hi @davidfowl, regarding removing DI from Startup. I'm guessing a lot of stuff that goes on in peoples Startups is a mix of actually starting the application and warming up the application. Starting it usually doesn't require access to the DI container other that being able to register the different service needed in the DI container.

Wouldn't a clean approach be to split it into Startup & Warmup, where Startup only can register services in the DI and configure the application and Warmup can only get already registered services injected into. This approach should also play nicely with other non-web application scenarios using the same HostBuilder.

Anyway, just an idea from a non-microsoft dev :)

thefringeninja commented 5 years ago

I don't get it. You are already free to supply your own Startup and inject all the dependencies you want, using new.

tidyui commented 5 years ago

Maybe I misunderstood the initial description @thefringeninja, but I was under the assumption that @davidfowl wanted to prohibit usage and access to the DI container during Startup in the future.

MattJeanes commented 5 years ago

As you mention IConfiguration is commonly injected into the Startup at the moment after being configured by the Web host in the Program.cs, how do you antipicate this working after these changes?

Tratcher commented 5 years ago

IConfiguration can be made available without DI, the host has a direct reference to it. Go look at the IWebHost.Configure and ConfigureServices APIs we have today that have first class access to IHostingEnvironment, IConfiguration, etc..

lsiddiquee commented 5 years ago

Apologies for a naive question. Does this imply potentially prepping this for non aspnet core scenario? On a partially related note, just yesterday I was looking for template and boiler plate code to write a service which can potentially run as windows service and/or linux daemon.

davidfowl commented 5 years ago

@lsiddiquee yes it does.

davidfowl commented 5 years ago

Proof of concept here https://github.com/davidfowl/GenericHostPOC.

Here's a working application build on 2.1 with a different implementation of the WebHostBuilder (backed by generic host). This approach has very few caveats and it's the one I think we'll take.

Things that outright won't work:

Things that need to be ported:

Beyond that everything seems to work.