Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
private sealed class
  • Loading branch information
halter73 committed Dec 6, 2021
commit f99b2af6f77e6a9ca94cf71752875c99664c6c2e
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public string? this[string key]
{
get
{
using var refCounter = _providerManager.GetReference();
return ConfigurationRoot.GetConfiguration(refCounter.Providers, key);
using var reference = _providerManager.GetReference();
return ConfigurationRoot.GetConfiguration(reference.Providers, key);
}
set
{
using var refCounter = _providerManager.GetReference();
ConfigurationRoot.SetConfiguration(refCounter.Providers, key, value);
using var reference = _providerManager.GetReference();
ConfigurationRoot.SetConfiguration(reference.Providers, key, value);
}
}

Expand All @@ -59,8 +59,8 @@ public string? this[string key]
/// <inheritdoc/>
public IEnumerable<IConfigurationSection> GetChildren()
{
using var refCounter = _providerManager.GetReference();
return this.GetChildrenImplementation(refCounter.Providers, path: null);
using var reference = _providerManager.GetReference();
return this.GetChildrenImplementation(reference.Providers, path: null);
}

IDictionary<string, object> IConfigurationBuilder.Properties => _properties;
Expand Down Expand Up @@ -91,9 +91,9 @@ IConfigurationBuilder IConfigurationBuilder.Add(IConfigurationSource source)

void IConfigurationRoot.Reload()
{
using (var refCounter = _providerManager.GetReference())
using (var reference = _providerManager.GetReference())
{
foreach (var provider in refCounter.Providers)
foreach (var provider in reference.Providers)
{
provider.Load();
}
Expand Down Expand Up @@ -153,7 +153,7 @@ private void DisposeRegistrations()
}
}

private class ConfigurationSources : IList<IConfigurationSource>
private sealed class ConfigurationSources : IList<IConfigurationSource>
{
private readonly List<IConfigurationSource> _sources = new();
private readonly ConfigurationManager _config;
Expand Down Expand Up @@ -234,14 +234,14 @@ IEnumerator IEnumerable.GetEnumerator()
}
}

private class ProviderManager : IDisposable
private sealed class ProviderManager : IDisposable
{
private readonly object _replaceProvidersLock = new object();
private RefCountedProviders _refCountedProviders = new(new List<IConfigurationProvider>());
private ProvidersReference _refCountedProviders = new(new List<IConfigurationProvider>());

public IEnumerable<IConfigurationProvider> Providers => _refCountedProviders.Providers;

public RefCountedProviders GetReference()
public ProvidersReference GetReference()
{
// Lock to ensure oldRefCountedProviders.Dispose() in ReplaceProviders() doesn't decrement ref count to zero
// before calling _refCountedProviders.AddRef().
Expand All @@ -255,11 +255,11 @@ public RefCountedProviders GetReference()
// Providers should never be concurrently modified. Reading during modification is allowed.
public void ReplaceProviders(List<IConfigurationProvider> providers)
{
RefCountedProviders oldRefCountedProviders = _refCountedProviders;
ProvidersReference oldRefCountedProviders = _refCountedProviders;

lock (_replaceProvidersLock)
{
_refCountedProviders = new RefCountedProviders(providers);
_refCountedProviders = new ProvidersReference(providers);
}

oldRefCountedProviders.Dispose();
Expand All @@ -277,11 +277,11 @@ public void AddProvider(IConfigurationProvider provider)
public void Dispose() => _refCountedProviders.Dispose();
}

private class RefCountedProviders : IDisposable
private sealed class ProvidersReference : IDisposable
{
private long _refCount = 1;

public RefCountedProviders(List<IConfigurationProvider> providers)
public ProvidersReference(List<IConfigurationProvider> providers)
{
Providers = providers;
}
Expand All @@ -305,7 +305,7 @@ public void Dispose()
}
}

private class ConfigurationBuilderProperties : IDictionary<string, object>
private sealed class ConfigurationBuilderProperties : IDictionary<string, object>
{
private readonly Dictionary<string, object> _properties = new();
private readonly ConfigurationManager _config;
Expand Down