Class ConfigManager
- Namespace
- Ecng.Configuration
- Assembly
- Ecng.Configuration.dll
Provides access to application configuration sections, groups, and services.
public static class ConfigManager
- Inheritance
-
ConfigManager
- Inherited Members
Properties
AppSettings
Gets the application settings.
public static NameValueCollection AppSettings { get; }
Property Value
InnerConfig
Gets the underlying configuration file used by the application.
public static Configuration InnerConfig { get; }
Property Value
Methods
GetGroup(string)
Returns the configuration section group specified by the section name.
public static ConfigurationSectionGroup GetGroup(string sectionName)
Parameters
sectionName
stringThe name of the configuration section group.
Returns
- ConfigurationSectionGroup
The configuration section group instance.
GetGroup(Type)
Returns the configuration section group matching the specified type, or null if not found.
public static ConfigurationSectionGroup GetGroup(Type sectionGroupType)
Parameters
sectionGroupType
TypeThe type of the configuration section group.
Returns
- ConfigurationSectionGroup
The configuration section group instance or null.
GetGroup<T>()
Returns the configuration section group of type T.
public static T GetGroup<T>() where T : ConfigurationSectionGroup
Returns
- T
The configuration section group instance of type T.
Type Parameters
T
The type of the configuration section group.
GetGroup<T>(string)
Returns the configuration section group of type T specified by the section name.
public static T GetGroup<T>(string sectionName) where T : ConfigurationSectionGroup
Parameters
sectionName
stringThe name of the configuration section group.
Returns
- T
The configuration section group instance of type T.
Type Parameters
T
The type of the configuration section group.
GetSection(string)
Returns the configuration section specified by the section name.
public static ConfigurationSection GetSection(string sectionName)
Parameters
sectionName
stringThe name of the configuration section.
Returns
- ConfigurationSection
The configuration section instance.
GetSection(Type)
Returns the configuration section matching the specified type, or null if not found.
public static ConfigurationSection GetSection(Type sectionType)
Parameters
sectionType
TypeThe type of the configuration section.
Returns
- ConfigurationSection
The configuration section instance or null.
GetSection<T>()
Returns the configuration section of type T.
public static T GetSection<T>() where T : ConfigurationSection
Returns
- T
The configuration section instance of type T.
Type Parameters
T
The type of the configuration section.
GetSection<T>(string)
Returns the configuration section of type T specified by the section name.
public static T GetSection<T>(string sectionName) where T : ConfigurationSection
Parameters
sectionName
stringThe name of the configuration section.
Returns
- T
The configuration section instance of type T.
Type Parameters
T
The type of the configuration section.
GetService<T>()
Retrieves the service of type T by the default name, using fallback if necessary.
public static T GetService<T>()
Returns
- T
The service instance.
Type Parameters
T
The type of the service.
GetService<T>(string)
Retrieves the service of type T by specified name, using fallback if necessary.
public static T GetService<T>(string name)
Parameters
name
stringThe unique name of the service.
Returns
- T
The service instance.
Type Parameters
T
The type of the service.
GetServices<T>()
Returns all distinct registered services of type T.
public static IEnumerable<T> GetServices<T>()
Returns
- IEnumerable<T>
An enumerable of service instances.
Type Parameters
T
The type of the services.
IsServiceRegistered<T>()
Checks if a service of type T is registered using the default name.
public static bool IsServiceRegistered<T>()
Returns
- bool
True if the service is registered; otherwise, false.
Type Parameters
T
The type of the service.
IsServiceRegistered<T>(string)
Checks if a service of type T with the provided name is registered.
public static bool IsServiceRegistered<T>(string name)
Parameters
name
stringThe unique name of the service.
Returns
- bool
True if the service is registered; otherwise, false.
Type Parameters
T
The type of the service.
RegisterService<T>(string, T)
Registers the specified service of type T with the provided name.
public static void RegisterService<T>(string name, T service)
Parameters
name
stringThe unique name to register the service.
service
TThe service instance.
Type Parameters
T
The type of the service to register.
RegisterService<T>(T)
Registers the specified service of type T using the default name.
public static void RegisterService<T>(T service)
Parameters
service
TThe service instance.
Type Parameters
T
The type of the service to register.
SubscribeOnRegister<T>(Action<T>)
Subscribes to the service registration event for the specified type.
public static void SubscribeOnRegister<T>(Action<T> registered)
Parameters
registered
Action<T>The action to invoke when a service is registered.
Type Parameters
T
The type of service to subscribe for.
TryGetService<T>()
Tries to retrieve the registered service of type T, returning default if not registered.
public static T TryGetService<T>()
Returns
- T
The service instance, or default if not registered.
Type Parameters
T
The type of the service.
TryGet<T>(string, T)
Tries to get a configuration value from the configuration file using the specified key.
public static T TryGet<T>(string name, T defaultValue = default)
Parameters
name
stringThe key name.
defaultValue
TThe default value if the key is not found or empty.
Returns
- T
The configuration value, or the default value if not found.
Type Parameters
T
The expected value type.
TryRegisterService<T>(T)
Registers the service of type T if it is not already registered.
public static void TryRegisterService<T>(T service)
Parameters
service
TThe service instance.
Type Parameters
T
The type of the service.
Events
ServiceFallback
Occurs when a service fallback is invoked to construct a service.
public static event Func<Type, string, object> ServiceFallback
Event Type
ServiceRegistered
Occurs when a service is registered.
public static event Action<Type, object> ServiceRegistered