-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
Priority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-minimal-hostingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Description
In my project, I created a custom configuration provider, which is mainly used to process .txt files.
After that, I added a custom configuration provider through the following code and found that the provider's Load method was called multiple times.
The following code is added through WebApplicationBuilder.Configuration.
/// <summary>
/// TXTConfigurationSource.Build() call multiple times
/// </summary>
[Fact]
public void TestWebApplicationBuilder()
{
var builder = WebApplication.CreateBuilder();
builder.Configuration.AddTXTConfiguration(options =>
{
options.Output = Output;
options.Path = Path.Combine(AppContext.BaseDirectory, "file.txt");
});
using var app = builder.Build();
var services = app.Services;
var configuration = services.GetRequiredService<IConfiguration>();
Assert.Equal("VALUE", configuration["TXT"]);
}However, if I use the Host.CreateDefaultBuilder().ConfigureAppConfiguration() method to add a custom configuration provider, the Load method will only be called once, which is what I expect.
/// <summary>
/// TXTConfigurationSource.Build() call once
/// </summary>
[Fact]
public void TestHostBuilder()
{
var builder = Host.CreateDefaultBuilder()
.ConfigureAppConfiguration((context, builder) =>
{
builder.AddTXTConfiguration(options =>
{
options.Output = Output;
options.Path = Path.Combine(AppContext.BaseDirectory, "file.txt");
});
});
var app = builder.Build();
var services = app.Services;
var configuration = services.GetRequiredService<IConfiguration>();
Assert.Equal("VALUE", configuration["TXT"]);
}Metadata
Metadata
Assignees
Labels
Priority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-minimal-hostingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

