-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from gsoft-inc/feature/cached-configuration-sou…
…rces Caching configuration sources to prevent duplicating configuration providers
- Loading branch information
Showing
10 changed files
with
70 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
src/GSoft.Extensions.Configuration.Substitution.Tests/ServiceCollectionTests.cs
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/GSoft.Extensions.Configuration.Substitution/CachedConfigurationSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace GSoft.Extensions.Configuration.Substitution; | ||
|
||
[DebuggerDisplay("CachedConfigurationSource({_underlyingConfigurationSourceType})")] | ||
internal sealed class CachedConfigurationSource : IConfigurationSource | ||
{ | ||
private readonly object _lockObject = new object(); | ||
private readonly IConfigurationSource _underlyingConfigurationSource; | ||
private readonly string _underlyingConfigurationSourceType; | ||
private volatile IConfigurationProvider? _configurationProvider; | ||
|
||
public CachedConfigurationSource(IConfigurationSource underlyingConfigurationSource) | ||
{ | ||
this._underlyingConfigurationSource = underlyingConfigurationSource ?? throw new ArgumentNullException(nameof(underlyingConfigurationSource)); | ||
this._underlyingConfigurationSourceType = this._underlyingConfigurationSource.GetType().Name; | ||
} | ||
|
||
public IConfigurationProvider Build(IConfigurationBuilder builder) | ||
{ | ||
if (this._configurationProvider != null) | ||
{ | ||
return this._configurationProvider; | ||
} | ||
|
||
lock (this._lockObject) | ||
{ | ||
if (this._configurationProvider != null) | ||
{ | ||
return this._configurationProvider; | ||
} | ||
|
||
this._configurationProvider = this._underlyingConfigurationSource.Build(builder); | ||
} | ||
|
||
return this._configurationProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
src/GSoft.Extensions.Configuration.Substitution/ConfigurationRootWrapper.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.