Created
July 21, 2014 06:05
-
-
Save brainded/5b7be95727fd4d317a7a to your computer and use it in GitHub Desktop.
Example of a Custom Configuration Section. Can be used in conjunction with Config Transforms to provide different custom configuration per build/environment.
This file contains hidden or 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
using System; | |
using System.Configuration; | |
namespace Example.Configuration | |
{ | |
internal class BobsBurgersConfiguration : ConfigurationSection | |
{ | |
/// <summary> | |
/// The BobsBurgers ConfigurationSection name. | |
/// </summary> | |
private readonly static string _bobsBurgersConfiguration = "bobsBurgersConfiguration"; | |
/// <summary> | |
/// The settings for the BobsBurgers ConfigurationSection. | |
/// </summary> | |
private static BobsBurgersConfiguration _settings = System.Configuration.ConfigurationManager.GetSection(_bobsBurgersConfiguration) as BobsBurgersConfiguration; | |
/// <summary> | |
/// Gets the settings. | |
/// </summary> | |
/// <value> | |
/// The settings. | |
/// </value> | |
public static BobsBurgersConfiguration Settings | |
{ | |
get | |
{ | |
return _settings; | |
} | |
} | |
/// <summary> | |
/// Gets the environment. | |
/// </summary> | |
/// <value> | |
/// The environment. | |
/// </value> | |
[ConfigurationProperty("environment", IsRequired = true)] | |
public string Environment | |
{ | |
get | |
{ | |
return (string)this["environment"]; | |
} | |
} | |
/// <summary> | |
/// Gets the public key. | |
/// </summary> | |
/// <value> | |
/// The public key. | |
/// </value> | |
[ConfigurationProperty("publicKey", IsRequired = true)] | |
public string PublicKey | |
{ | |
get | |
{ | |
return (string)this["publicKey"]; | |
} | |
} | |
/// <summary> | |
/// Gets the private key. | |
/// </summary> | |
/// <value> | |
/// The private key. | |
/// </value> | |
[ConfigurationProperty("privateKey", IsRequired = true)] | |
public string PrivateKey | |
{ | |
get | |
{ | |
return (string)this["privateKey"]; | |
} | |
} | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
For more information on how to configure your ASP.NET application, please visit | |
http://go.microsoft.com/fwlink/?LinkId=301880 | |
--> | |
<configuration> | |
<configSections> | |
<section name="bobsBurgersConfiguration" type="Example.Configuration.BobsBurgersConfiguration" allowLocation="true" allowDefinition="Everywhere"></section> | |
</configSections> | |
<bobsBurgersConfiguration environment="DEV" publicKey="PUBLICKEY" privateKey="PRIVATEKEY" /> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment