Open drauch opened 15 hours ago
Tagging subscribers to this area: @dotnet/area-extensions-configuration See info in area-owners.md if you want to be subscribed.
You should still be able to register your own singleton instance the exact same way using ConfigureServices
:
.ConfigureServices((context, services) =>
{
OurConfigurationUtility.SetUp(context.Configuration);
services.AddSingleton<IConfiguration>(context.Configuration);
})
I'm just confused by your usage there... you pass in the configuration
, and then your method does mutations to it? Regardless... I believe the above should still work, although I'm not sure whether that registration will be overridden by the Host.Build()
call later.
Why do you have this external configuration method in the first place?
Can't you do something like:
hostBuilder.ConfigureAppConfiguration((context, config) =>
{
config.Sources.Clear(); // Clear existing configuration sources
// then add your configuration the config
});
This issue has been marked needs-author-action
and may be missing some important information.
For internal reasons we create and validate the IConfiguration instance before building hosts. The .NET 6 WebApplicationBuilder lets us register this instance directly at the container:
However, for our non-web background services we can't do the same with
HostBuilder
. To our knowledge there is only theConfigureAppConfiguration
method which already puts in some defaults and lets you work with aConfigurationBuilder
but there is no way to put a finishedIConfiguration
instance in, is there?Best regards, D.R.