-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add support for clearing ConfigurationManager sources (was possible in version 5) #61675
Comments
This is the workaround: var builder = WebApplication.CreateBuilder(args);
((IConfigurationBuilder)builder.Configuration).Sources.Clear(); Moving this to the runtime cc @halter73 |
Tagging subscribers to this area: @maryamariyan, @safern Issue DetailsProblem descriptionPrior to version 6.0 with the old style application startup it was possible for an application to define how configuration file should be loaded by clearing up the configuration sources and by adding the configuration items in the desired order. With version 6 it is now impossible to
ProposalAs it is always possible to add new configuration sources to the ConfigurationManager class, the cleanest approach which would not break the current encapsulation would be to add a clear() method to the ConfigurationManager class.
|
Thanks a lot for the workaround ! |
@halter73 - any thoughts on this? |
I see three options:
I'm leaning towards option 1. The only reason we didn't make The argument for option 3 is that removing sources is far less common than adding them so the vast majority of interaction with the |
I like 1 |
namespace Microsoft.Extensions.Configuration
{
public sealed class ConfigurationManager : IConfigurationBuilder, IConfigurationRoot, IDisposable
{
- IList<IConfigurationSource> IConfigurationBuilder.Sources { get; }
+ IList<IConfigurationSource> Sources { get; } |
@maryamariyan I moved this to the 7.0.0 milestone and marked it ready for review. |
namespace Microsoft.Extensions.Configuration
{
public partial sealed class ConfigurationManager
{
// Currently explicit:
// IList<IConfigurationSource> IConfigurationBuilder.Sources { get; }
// Now implicit:
public IList<IConfigurationSource> Sources { get; }
}
} |
I don't think clearing both is helpful. It could be used by third-party extension methods to track other state, but I think most people who clear |
@maryamariyan should this be marked up for grabs in case @fredjeck or someone else is interested in doing it before we get to it? |
marked up for grabs |
ConfigurationManager.Sources is now a public property rather than an explicit interface implementation of ConfigurationBuilder.Sources. dotnet#61675
* Make ConfigurationManager.Sources public ConfigurationManager.Sources is now a public property rather than an explicit interface implementation of ConfigurationBuilder.Sources. #61675
Resolved by #66485 |
* Make ConfigurationManager.Sources public ConfigurationManager.Sources is now a public property rather than an explicit interface implementation of ConfigurationBuilder.Sources. dotnet#61675
Problem description
Prior to version 6.0 with the old style application startup it was possible for an application to define how configuration file should be loaded by clearing up the configuration sources and by adding the configuration items in the desired order.
A use case is for instance a shared library with a baseline configuration which needs to be "injected" into the Configuration before the appsettings.* files. so that developers just need to implement minimum overrides in their appsettings files.
With version 6 it is now impossible to
Proposal
As it is always possible to add new configuration sources to the ConfigurationManager class, the cleanest approach which would not break the current encapsulation would be to add a clear() method to the ConfigurationManager class.
The text was updated successfully, but these errors were encountered: