Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Like WebApplicationBuilder allow us to put a finished IConfiugration instance into a HostBuilder #110051

Open
drauch opened this issue Nov 21, 2024 · 4 comments
Labels
area-Extensions-Configuration needs-author-action An issue or pull request that requires more info or actions from the author. question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@drauch
Copy link

drauch commented Nov 21, 2024

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:

var builder = WebApplicationBuilder.CreateBuilder();
OurConfigurationUtility.SetUp(builder.Configuration);

builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
 
var startup = new Startup(builder.Configuration);
startup.ConfigureServices(builder.Services);
 
var app = builder.Build();
 
startup.Configure(app, app.Environment);
 
app.Run();

However, for our non-web background services we can't do the same with HostBuilder. To our knowledge there is only the ConfigureAppConfiguration method which already puts in some defaults and lets you work with a ConfigurationBuilder but there is no way to put a finished IConfiguration instance in, is there?

Best regards,
D.R.

@drauch drauch added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Nov 21, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 21, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

@julealgon
Copy link

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?

@tarekgh
Copy link
Member

tarekgh commented Nov 21, 2024

Can't you do something like:

hostBuilder.ConfigureAppConfiguration((context, config) =>
{
    config.Sources.Clear(); // Clear existing configuration sources
    // then add your configuration the config
});

@tarekgh tarekgh added question Answer questions and provide assistance, not an issue with source code or documentation. needs-author-action An issue or pull request that requires more info or actions from the author. and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation untriaged New issue has not been triaged by the area owner labels Nov 21, 2024
@tarekgh tarekgh added this to the Future milestone Nov 21, 2024
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Configuration needs-author-action An issue or pull request that requires more info or actions from the author. question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

3 participants