.NET › Configuration & Options
How does the order of configuration provider registration affect which value wins when the same key is defined in multiple sources?
IntermediateAnswer
Configuration providers are evaluated in the order they're added to the ConfigurationBuilder, with each subsequently added provider's values overriding any previously set value for the same key -- meaning provider registration order directly determines precedence, which is why understanding and controlling this order (files first, then environment variables, then command-line args, as the conventional pattern) is essential for predictable configuration behavior across environments.
var builder = WebApplication.CreateBuilder(args);
// Default order already applied: appsettings.json -> appsettings.{Env}.json -> user secrets -> env vars -> command line
// Adding a custom source LAST gives it HIGHEST precedence
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string> {
["Override:Key"] = "this wins over everything registered before it"
});Real-world example A debugging session reveals a setting isn't taking effect because a custom configuration source was registered before the environment variable provider instead of after, causing the environment variable to silently override the intended custom value.