Class ConfigurationManager
- Namespace
- Dynamicweb.Configuration
- Assembly
- Dynamicweb.Configuration.dll
Class for managing configuration values. Uses a provider that defines where configuration values are stored.
The default configuration manager is accessed through SystemConfiguration which uses the XmlConfigurationProvider to return values from settings stored in /Files/*.config files.
public class ConfigurationManager
- Inheritance
-
ConfigurationManager
- Inherited Members
- Extension Methods
Examples
namespace Dynamicweb.Configuration.Examples
{
class ConfigurationSample
{
void Configure()
{
// Setting a configuration value
SystemConfiguration.Instance.SetValue("/Globalsettings/Modules/MyModule/Feature", true);
// Getting a configuration setting as a string value
string dbserver = SystemConfiguration.Instance.GetValue("/Globalsettings/System/Database/Server");
// Getting a configuration setting as an integer value
int maxAttempts = SystemConfiguration.Instance.GetInt32("/Globalsettings/Modules/MyModule/MaxAttempts");
// Getting a configuration setting as a boolean value
bool useFeature = SystemConfiguration.Instance.GetBoolean("/Globalsettings/Modules/MyModule/UseFeature");
// Getting a configuration setting using TryGet
string apiKey;
if (SystemConfiguration.Instance.TryGet("/Globalsettings/Modules/MyModule/ApiKey", out apiKey))
{
if (!string.IsNullOrEmpty(apiKey))
{
}
}
}
}
}
Remarks
Implement IConfigurationProvider to add configuration providers that can store and retrieve settings from other sources.
Constructors
ConfigurationManager()
Creates a new instance of ConfigurationManager.
public ConfigurationManager()
Methods
AddProvider(IConfigurationProvider)
Adds an instance of IConfigurationProvider. This enables multiple providers to contribute the the same ConfigurationManager.
public void AddProvider(IConfigurationProvider provider)
Parameters
provider
IConfigurationProvider- The provider to add.
AddProviderPriority(IConfigurationProvider)
Adds an instance of IConfigurationProvider as the first provider in the provider list giving it priority over the system configuration provider.
This enables multiple providers to contribute the the same ConfigurationManager.
public void AddProviderPriority(IConfigurationProvider provider)
Parameters
provider
IConfigurationProvider- The provider to add.
Contains(string)
Determines whether the configuration contains the specified key.
public virtual bool Contains(string key)
Parameters
key
string- The key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
Returns
- bool
true
if the configuration contains an entry with the specified key; otherwise,
.false
Get(string)
Gets the string value for the specified key.
[Obsolete("Get is obsolete. Use GetValue instead", true)]
public virtual string Get(string key)
Parameters
key
string- The key that represents the value to get, e.g. "/Globalsettings/System/Database/Trusted"
Returns
GetBoolean(string)
Gets the bool value for the specified key.
public virtual bool GetBoolean(string key)
Parameters
key
string- The key that represents the value to get, e.g. "/Globalsettings/System/Database/Trusted"
Returns
- bool
- The value converted to bool if the key exists and is a valid boolean string in configuration file (True, 1, On), otherwise
.false
GetInt32(string)
Gets the int value for the specified key.
public virtual int GetInt32(string key)
Parameters
key
string- The key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
Returns
GetKeys()
Gets all keys that can be used to get or set data.
public ICollection<string> GetKeys()
Returns
- ICollection<string>
- keys
GetValue(string)
Gets the string value for the specified key.
public virtual string GetValue(string key)
Parameters
key
string- The key that represents the value to get, e.g. "/Globalsettings/System/Database/Trusted"
Returns
Set<T>(Dictionary<string, string>)
Sets a collection configuration entries.
[Obsolete("Use SetValue instead")]
public virtual void Set<T>(Dictionary<string, string> keyValues) where T : IConvertible
Parameters
keyValues
Dictionary<string, string>- The key/value pairs to set.
Type Parameters
T
Set<T>(string, T)
Sets value of the entry with the specified key.
[Obsolete("Use SetValue instead")]
public virtual void Set<T>(string key, T value) where T : IConvertible
Parameters
key
string- The key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
value
T- The value of the element to add to the configuration file. Should be simple value types like string, bool, int or double.
Type Parameters
T
- The type of the value.
SetValue(Dictionary<string, string>)
Sets a collection configuration entries.
public virtual void SetValue(Dictionary<string, string> keyValues)
Parameters
keyValues
Dictionary<string, string>- The key/value pairs to set.
SetValue<T>(Dictionary<string, string>)
Sets the value.
[Obsolete("Use non-generic SetValue instead.")]
public virtual void SetValue<T>(Dictionary<string, string> keyValues) where T : IConvertible
Parameters
keyValues
Dictionary<string, string>- The key values.
Type Parameters
T
SetValue<T>(string, T)
Sets value of the entry with the specified key.
public virtual void SetValue<T>(string key, T value) where T : IConvertible
Parameters
key
string- The key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
value
T- The value of the element to add to the configuration file. Should be simple value types like string, bool, int or double.
Type Parameters
T
- The type of the value.
TryGet<T>(string, out T)
Attempts to get the value associated with the specified key.
public virtual bool TryGet<T>(string key, out T value) where T : IConvertible
Parameters
key
string- The key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
value
T- When this method returns, contains the value associated with the specified key, or the default value of the type if the key was not found.
Returns
- bool
true
if the specified key was found; otherwise,false
.
Type Parameters
T
- The type of the value.