-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Environment:
Microsoft Visual Studio Community 2022
Version 17.1.0
VisualStudio.17.Release/17.1.0+32210.238
Microsoft .NET Framework
Version 4.8.04084
Creating a web application using .Net 6.0 ...
I have an app_settings class with a load() method. The method simply adds configuration keys/values from six sources. A stripped down version is shown below:
public static void load( Microsoft.AspNetCore.Builder.WebApplicationBuilder web_app_builder )
{
// Start clean - clear all sources ...
( ( IConfigurationBuilder )web_app_builder.Configuration ).Sources.Clear();
// Common settings used by all environments ...
web_app_builder.Configuration.AddJsonFile( "appsettings_common.json", optional: false, reloadOnChange: false );
// Add environment variables ...
web_app_builder.Configuration.AddEnvironmentVariables();
// Add development settings ...
web_app_builder.Configuration.AddJsonFile( "appsettings_development.json", optional: false, reloadOnChange: false );
// Add an in-memory collection of keys / values ...
System.Collections.Generic.Dictionary<String, String> in_memory_dict = new() {
{ "in_memory_key0", "in_memory_value0" },
{ "in_memory_key1", "in_memory_value1" }
};
web_app_builder.Configuration.AddInMemoryCollection( in_memory_dict );
// Add user secrets ...
Assembly app_assembly = Assembly.GetEntryAssembly();
if ( app_assembly is not null )
{
web_app_builder.Configuration.AddUserSecrets( app_assembly );
}
// Add command line args ...
cmd_line_args = System.Environment.GetCommandLineArgs();
if ( cmd_line_args is not null )
{
web_app_builder.Configuration.AddCommandLine( cmd_line_args );
}
// Save configuration ...
app_settings.config = web_app_builder.Configuration;
}
Just for fun, I thought I would check the configuration providers that were added, so I used the following:
Console.WriteLine( "CONFIGURATION PROVIDERS:" );
IEnumerable<IConfigurationProvider> config_providers = app_settings.config.Providers;
int load_order = 0;
foreach ( IConfigurationProvider config_provider in config_providers )
{
load_order++;
Console.WriteLine( $"Load order: {load_order}, Provider: {config_provider.GetType().Name}" );
}
... and the output shows the following:
CONFIGURATION PROVIDERS:
Load order: 1, Provider: JsonConfigurationProvider
Load order: 2, Provider: EnvironmentVariablesConfigurationProvider
Load order: 3, Provider: JsonConfigurationProvider
Load order: 4, Provider: MemoryConfigurationProvider
Load order: 5, Provider: JsonConfigurationProvider
Load order: 6, Provider: CommandLineConfigurationProvider
Load order: 7, Provider: IgnoreFirstLoadConfigurationProvider // <-- Where does this come from??
The first six providers match the code in the load() method above and were expected - but it seems the framework is magically inserting IgnoreFirstLoadConfigurationProvider !?
I cannot seem to find where this provider is documented. It does not appear in the list of Configuration Providers from the official documentation.
What is the IgnoreFirstLoadConfigurationProvider, and what is it doing? (perhaps something to do with Hot Reload?).
Thanks in advance.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 0eb4d762-3910-2c57-8741-3306c15537b6
- Version Independent ID: ba2254a0-ea8e-9b28-e94b-edd0fc58c043
- Content: Configuration in ASP.NET Core
- Content Source: aspnetcore/fundamentals/configuration/index.md
- Product: aspnet-core
- Technology: aspnetcore-fundamentals
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande