Normally with ASP.NET Core projects, I have access to the IWebHostBuilder
creation, upon which I can register services and build configuration, and then I can get into a Startup
class where I can inject any of the services or configurations that were registered while building the host. I use this two-stage approach quite often, as I usually need some services available within Startup to finish registering everything else.
Now I'm working on a Generic Host headless app, adding a BackgroundService
with AddHostedService<T>
. There is no Startup
class in this scenario, so it seems all my dependencies have to be registered while creating the HostBuilder
. I'm not able to use my normal services because of the lack of the second registration step.
When using the Generic Host/non-HTTP/BackgroundService/AddHostedService approach, how can I get two stages of dependency registration as I do in Web projects?