dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.47k stars 10.03k forks source link

The "default" IConfiguration provided to Startup contains multiple nested providers with duplicates/triplicates in places #17253

Closed ryangribble closed 4 years ago

ryangribble commented 4 years ago

Describe the bug

The "default" IConfiguration provided to Startup seems overly complex, containing multiple nested providers with duplicates/triplicates in places. This causes difficulty in reasoning about how the default configuration setup should work!

I'm mostly interested in whether this is intentional (and if so what the reasoning is) or whether it is inadvertent (passing around builders through various parts of the framework, with multiple places adding providers onto an already complicated provider list?)

To Reproduce

dotnet new webapi

Set a breakpoint in Startup.cs Configure() method and inspect the Configuration.Providers property at run time.

It contains 5 top level providers and a total of 3 nested levels, with EnvironmentVariables in the list 3 times and CommandLine being in the list 2 times.

The heirarchy is as follows (indentation showing the child items of the ChainedConfigurationProviders):

image

This seems overly complicated and in my case has led to unexpected behaviour trying to reason about how configuration values are ultimately being surfaced!

Further technical details

3.0.0

.NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26

Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support): Version: 3.0.0 Commit: 7d57652f33

.NET Core SDKs installed: 1.0.0 [C:\Program Files\dotnet\sdk] 1.0.1 [C:\Program Files\dotnet\sdk] 1.0.4 [C:\Program Files\dotnet\sdk] 1.1.0 [C:\Program Files\dotnet\sdk] 2.0.0 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

ryangribble commented 4 years ago

NOTE: It does appear the EnvionmentVariables providers have different prefixes "ASPNETCORE_" "DOTNET_" and "" so I guess that does start to make things clearly if they come from different areas/layers of the eco system...

javiercn commented 4 years ago

@ryangribble thanks for contacting us.

As you mention, this is this way because the information comes from multiple sources at different levels, for example hosting has a provider that handles ASPNETCORE_... environment variables that are used to set up things like listening urls etc.

See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.0#default-configuration for more details

/cc:@tratcher in case he wants to add anything else.

Hope that helps