-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ConfigurationManager configuration source and provider
- Loading branch information
1 parent
fac69a9
commit 35c0a94
Showing
18 changed files
with
790 additions
and
52 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
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
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
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
63 changes: 63 additions & 0 deletions
63
...xtensions.Configuration.ConfigurationManager/ConfigurationManagerConfigurationProvider.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,63 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Configuration; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.Extensions.Configuration.ConfigurationManager | ||
{ | ||
/// <summary> | ||
/// A <see cref="System.Configuration.ConfigurationManager" /> based <see cref="ConfigurationProvider" />. | ||
/// </summary> | ||
public class ConfigurationManagerConfigurationProvider : ConfigurationProvider | ||
{ | ||
//private readonly System.Configuration.ConfigurationManager configurationManager; | ||
/// <summary> | ||
/// The prefix | ||
/// </summary> | ||
private string prefix; | ||
|
||
/// <summary> | ||
/// The skip connection strings | ||
/// </summary> | ||
private bool skipConnectionStrings; | ||
|
||
/// <summary> | ||
/// The application settings enumeration mode | ||
/// </summary> | ||
private NameValueCollectionEnumerationMode appSettingsEnumerationMode; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConfigurationManagerConfigurationProvider" /> class. | ||
/// </summary> | ||
/// <param name="prefix">The prefix.</param> | ||
/// <param name="skipConnectionStrings">if set to <see langword="true" /> skip loading <see cref="System.Configuration.ConfigurationManager.ConnectionStrings" />.</param> | ||
/// <param name="appSettingsEnumerationMode">The application settings enumeration mode.</param> | ||
public ConfigurationManagerConfigurationProvider(string prefix, bool skipConnectionStrings, NameValueCollectionEnumerationMode appSettingsEnumerationMode) | ||
{ | ||
this.prefix = prefix; | ||
this.skipConnectionStrings = skipConnectionStrings; | ||
this.appSettingsEnumerationMode = appSettingsEnumerationMode; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void Load() | ||
{ | ||
var data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||
|
||
foreach (var pair in System.Configuration.ConfigurationManager.AppSettings.ToKeyValuePairEnumerable(this.appSettingsEnumerationMode, this.prefix)) | ||
{ | ||
data.Add(pair.Key, pair.Value); | ||
} | ||
|
||
if (!this.skipConnectionStrings) | ||
{ | ||
foreach (var pair in System.Configuration.ConfigurationManager.ConnectionStrings.ToKeyValuePairEnumerable()) | ||
{ | ||
data.Add(pair.Key, pair.Value); | ||
} | ||
} | ||
|
||
this.Data = data; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
....Extensions.Configuration.ConfigurationManager/ConfigurationManagerConfigurationSource.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,34 @@ | ||
namespace Microsoft.Extensions.Configuration.ConfigurationManager | ||
{ | ||
/// <summary> | ||
/// Represents a <see cref="ConfigurationManager"/> as an <see cref="IConfigurationSource"/>. | ||
/// </summary> | ||
public class ConfigurationManagerConfigurationSource : IConfigurationSource | ||
{ | ||
/// <summary> | ||
/// A prefix used to filter <see cref="System.Configuration.ConfigurationManager.AppSettings" />. | ||
/// </summary> | ||
/// <value>The prefix.</value> | ||
public string Prefix { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to skip loading <see cref="System.Configuration.ConfigurationManager.ConnectionStrings" />. | ||
/// </summary> | ||
/// <value><see langword="true" /> if skip loading <see cref="System.Configuration.ConfigurationManager.ConnectionStrings" />; otherwise, <see langword="false" />.</value> | ||
public bool SkipConnectionStrings { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="System.Configuration.ConfigurationManager.AppSettings" /> <see cref="NameValueCollectionEnumerationMode">enumeration mode</see>. | ||
/// </summary> | ||
/// <value>The <see cref="System.Configuration.ConfigurationManager.AppSettings" /> <see cref="NameValueCollectionEnumerationMode">enumeration mode</see>.</value> | ||
public NameValueCollectionEnumerationMode AppSettingsEnumerationMode { get; set; } | ||
|
||
/// <summary> | ||
/// Builds the <see cref="ConfigurationManagerConfigurationProvider"/> for this source. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param> | ||
/// <returns>The <see cref="ConfigurationManagerConfigurationProvider"/> built for this source.</returns> | ||
public IConfigurationProvider Build(IConfigurationBuilder builder) | ||
=> new ConfigurationManagerConfigurationProvider(this.Prefix, this.SkipConnectionStrings, this.AppSettingsEnumerationMode); | ||
} | ||
} |
Oops, something went wrong.