Class ConfigurationManager
- Namespace
- Dynamicweb.Configuration
- Assembly
- Dynamicweb.Core.dll
Class for managing configuration values. Uses a provider that defines where configuration values are stored.
The default configuration manager is accessed through System
- Inheritance
-
Configuration
Manager
- Derived
- 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 IConfiguration
Methods
AddProvider(IConfigurationProvider)
Adds an instance of IConfiguration
Parameters
provider
IConfigurationProvider The provider to add.
AddProviderPriority(IConfigurationProvider)
Adds an instance of IConfiguration
Parameters
provider
IConfigurationProvider The provider to add.
Contains(string)
Determines whether the configuration contains the specified key.
Parameters
key
stringThe 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
GetBoolean(string)
Gets the bool value for the specified key.
Parameters
key
stringThe 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
GetDouble(string)
Gets the double value for the specified key.
Parameters
key
stringThe key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
Returns
GetInt32(string)
Gets the int value for the specified key.
Parameters
key
stringThe 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.
Returns
- ICollection<string>
keys
GetValue(string)
Gets the string value for the specified key.
Parameters
key
stringThe key that represents the value to get, e.g. "/Globalsettings/System/Database/Trusted"
Returns
SetValue(Dictionary<string, string>)
Sets a collection configuration entries.
Parameters
keyValues
Dictionary<string, string>The key/value pairs to set.
SetValue<T>(string, T)
Sets value of the entry with the specified key.
Parameters
key
stringThe key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
value
TThe 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.
Parameters
key
stringThe key that represents the value, e.g. "/Globalsettings/System/Database/Trusted"
value
TWhen 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.