Consider exposing IConfiguration from IHostBuilder #1171
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-Extensions-Hosting
feature-request
Milestone
Calling
Host.CreateDefaultBuilder
automatically buildsIConfiguration
with a number of useful, very standardized rules. However, that configuration information is only available fromHostBuilderContext
via delegate-consuming config methods likeConfigureServices
lambdas.It would be useful if that configuration information was available either directly from
IHostBuilder
(or perhapsIHostBuilderContext
could be exposed instead). I have scenarios where I need to call asynchronous methods during startup which require configuration information. I've run across this building a variety of different types of applications, such as those that run on Azure (for example, Key Vault calls are async), building Orleans apps (connect a cluster-client and register it for injection), various database calls during startup, and so on. I suppose this is the same reason everyone wishes we had async config methods in ASP.NET Startup.cs.Currently I'm "stealing" a reference to configuration with a dummy call to
ConfigureServices
:It works, but it's pretty clearly a hack. I can't put the async call inside the lambda for a less hacky approach because void-returning async lambdas can't be awaited:
The text was updated successfully, but these errors were encountered: