ConfigManager

Ecng.Configuration

Provides access to application configuration sections, groups, and services.

Свойства

AppSettings
public static NameValueCollection AppSettings { get; }
value = ConfigManager.AppSettings

Gets the application settings, or where the host has no configuration system to read them from.

InnerConfig
public static Configuration InnerConfig { get; }
value = ConfigManager.InnerConfig

Gets the underlying configuration file used by the application.

Методы

GetGroup
public static ConfigurationSectionGroup GetGroup(Type sectionGroupType)
result = ConfigManager.GetGroup(sectionGroupType)

Returns the configuration section group matching the specified type, or null if not found.

sectionGroupType
The type of the configuration section group.

Возвращает: The configuration section group instance or null.

GetGroup
public static ConfigurationSectionGroup GetGroup(string sectionName)
result = ConfigManager.GetGroup(sectionName)

Returns the configuration section group specified by the section name.

sectionName
The name of the configuration section group.

Возвращает: The configuration section group instance.

GetGroup``1
public static T GetGroup<T>()
result = ConfigManager.GetGroup()

Returns the configuration section group of type T.

Возвращает: The configuration section group instance of type T.

GetGroup``1
public static T GetGroup<T>(string sectionName)
result = ConfigManager.GetGroup(sectionName)

Returns the configuration section group of type T specified by the section name.

sectionName
The name of the configuration section group.

Возвращает: The configuration section group instance of type T.

GetSection
public static ConfigurationSection GetSection(Type sectionType)
result = ConfigManager.GetSection(sectionType)

Returns the configuration section matching the specified type, or null if not found.

sectionType
The type of the configuration section.

Возвращает: The configuration section instance or null.

GetSection
public static ConfigurationSection GetSection(string sectionName)
result = ConfigManager.GetSection(sectionName)

Returns the configuration section specified by the section name.

sectionName
The name of the configuration section.

Возвращает: The configuration section instance.

GetSection``1
public static T GetSection<T>()
result = ConfigManager.GetSection()

Returns the configuration section of type T.

Возвращает: The configuration section instance of type T.

GetSection``1
public static T GetSection<T>(string sectionName)
result = ConfigManager.GetSection(sectionName)

Returns the configuration section of type T specified by the section name.

sectionName
The name of the configuration section.

Возвращает: The configuration section instance of type T.

GetServices``1
public static IEnumerable<T> GetServices<T>()
result = ConfigManager.GetServices()

Returns all distinct registered services of type T.

Возвращает: An enumerable of service instances.

GetService``1
public static T GetService<T>()
result = ConfigManager.GetService()

Retrieves the service of type T by the default name, using fallback if necessary.

Возвращает: The service instance.

GetService``1
public static T GetService<T>(string name)
result = ConfigManager.GetService(name)

Retrieves the service of type T by specified name, using fallback if necessary.

name
The unique name of the service.

Возвращает: The service instance.

IsServiceRegistered``1
public static bool IsServiceRegistered<T>()
result = ConfigManager.IsServiceRegistered()

Checks if a service of type T is registered using the default name.

Возвращает: True if the service is registered; otherwise, false.

IsServiceRegistered``1
public static bool IsServiceRegistered<T>(string name)
result = ConfigManager.IsServiceRegistered(name)

Checks if a service of type T with the provided name is registered.

name
The unique name of the service.

Возвращает: True if the service is registered; otherwise, false.

RegisterService``1
public static void RegisterService<T>(T service)
ConfigManager.RegisterService(service)

Registers the specified service of type T using the default name.

service
The service instance.
RegisterService``1
public static void RegisterService<T>(string name, T service)
ConfigManager.RegisterService(name, service)

Registers the specified service of type T with the provided name.

name
The unique name to register the service.
service
The service instance.
SubscribeOnRegister``1
public static void SubscribeOnRegister<T>(Action<T> registered)
ConfigManager.SubscribeOnRegister(registered)

Subscribes to the service registration event for the specified type.

registered
The action to invoke when a service is registered.
TryGetService``1
public static T TryGetService<T>()
result = ConfigManager.TryGetService()

Tries to retrieve the registered service of type T, returning default if not registered.

Возвращает: The service instance, or default if not registered.

TryGet``1
public static T TryGet<T>(string name, T defaultValue)
result = ConfigManager.TryGet(name, defaultValue)

Tries to get a configuration value from the configuration file using the specified key.

name
The key name.
defaultValue
The default value if the key is not found or empty.

Возвращает: The configuration value, or the default value if not found.

TryRegisterService``1
public static void TryRegisterService<T>(T service)
ConfigManager.TryRegisterService(service)

Registers the service of type T if it is not already registered.

service
The service instance.

События

ServiceFallback
public static event Func<Type, string, object> ServiceFallback
ConfigManager.ServiceFallback += handler

Occurs when a service fallback is invoked to construct a service.

ServiceRegistered
public static event Action<Type, object> ServiceRegistered
ConfigManager.ServiceRegistered += handler

Occurs when a service is registered.