ConfigManager
Provides access to application configuration sections, groups, and services.
プロパティ
public static NameValueCollection AppSettings { get; }
value = ConfigManager.AppSettings
Gets the application settings, or where the host has no configuration system to read them from.
public static Configuration InnerConfig { get; }
value = ConfigManager.InnerConfig
Gets the underlying configuration file used by the application.
メソッド
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.
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.
public static T GetGroup<T>()
result = ConfigManager.GetGroup()
Returns the configuration section group of type T.
戻り値: The configuration section group instance of type T.
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.
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.
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.
public static T GetSection<T>()
result = ConfigManager.GetSection()
Returns the configuration section of type T.
戻り値: The configuration section instance of type T.
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.
public static IEnumerable<T> GetServices<T>()
result = ConfigManager.GetServices()
Returns all distinct registered services of type T.
戻り値: An enumerable of service instances.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
イベント
public static event Func<Type, string, object> ServiceFallback
ConfigManager.ServiceFallback += handler
Occurs when a service fallback is invoked to construct a service.
public static event Action<Type, object> ServiceRegistered
ConfigManager.ServiceRegistered += handler
Occurs when a service is registered.