-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-Configuration
Milestone
Description
Background and motivation
When working on #86146 I've realized that ConfigurationBuilder.Build returns an instance of IConfigurationRoot, which does not derive from IDisposable, but all implementations of IConfigurationRoot implement IDisposable. So the users need to cast the result returned by ConfigurationBuilder.Build to IDisposable and call Dispose themselves to cleanup the resources properly.
IConfigurationRoot config = new ConfigurationBuilder().AddXmlFile("settings.xml", false, true).Build();
(config as IDisposable)?.Dispose();API Proposal
namespace Microsoft.Extensions.Configuration;
- public interface IConfigurationRoot : IConfiguration
+ public interface IConfigurationRoot : IConfiguration, IDisposable
{
/// <summary>
/// Force the configuration values to be reloaded from the underlying <see cref="IConfigurationProvider"/>s.
/// </summary>
void Reload();
/// <summary>
/// The <see cref="IConfigurationProvider"/>s for this configuration.
/// </summary>
IEnumerable<IConfigurationProvider> Providers { get; }
}API Usage
using IConfigurationRoot config = new ConfigurationBuilder().AddXmlFile("settings.xml", false, true).Build();Alternative Designs
No response
Risks
Any custom implementations of IConfigurationRoot that don't implement IDisposable will have to implement it, moreover users of IConfigurationRoot will most likely get a compiler warning about not disposing the instance.
Without introducing the mentioned changes we risk common resource leaks like in #86146.
MaceWindu, campersau and ShreyasJejurkar
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-Configuration