Configuration
On this page
Namespace: Nalix.Environment.Configuration (and Nalix.Environment.Configuration.Binding)
Assembly: Nalix.Environment
The Nalix.Environment configuration system binds .ini files to strongly-typed ConfigurationLoader classes using compile-time code generated by ConfigurationGenerator (zero runtime reflection).
Source Mapping
src/Nalix.Environment/Configuration/ConfigurationManager.cssrc/Nalix.Environment/Configuration/Binding/ConfigurationLoader.cssrc/Nalix.Environment/Configuration/Binding/ConfigurationLoader.SectionName.cssrc/Nalix.Environment/Configuration/Binding/IniConfig.csanalyzers/Nalix.Analyzers.Generators/ConfigurationGenerator.cs
ConfigurationManager
ConfigurationManager (public sealed class ConfigurationManager : IDisposable) manages the active .ini file (defaulting to <Directories.ConfigurationDirectory>/default.ini), debounced FileSystemWatcher reloads (300ms), and the thread-safe cache of ConfigurationLoader instances.
Public Properties & Methods
| Member | Signature | Description |
|---|---|---|
Instance | public static ConfigurationManager Instance { get; } | Global singleton instance. |
ConfigFilePath | public string ConfigFilePath { get; } | Absolute path to the active .ini file. |
ConfigFileExists | public bool ConfigFileExists { get; } | true if the active .ini file exists on disk. |
LastReloadTime | public DateTime LastReloadTime { get; } | UTC timestamp of the most recent configuration reload. |
Get<TClass>() | public TClass Get<TClass>() where TClass : ConfigurationLoader, new() | Resolves or initializes the cached TClass options instance from the active .ini file. |
Get<TClass>(string, bool) | public TClass Get<TClass>(string configFilePath, bool autoReload = true) where TClass : ConfigurationLoader, new() | Switches the active .ini file to configFilePath and resolves TClass. |
MarkManuallyConfigured<TClass>() | public void MarkManuallyConfigured<TClass>() where TClass : ConfigurationLoader | Marks TClass as configured in code so .ini reloads emit a warning when overwriting programmatic changes. |
SetConfigFilePath | public void SetConfigFilePath(string newConfigFilePath, bool autoReload = true) | Switches the active .ini file path (must reside under Directories.ConfigurationDirectory; throws TimeoutException if a reload is already in progress). |
UpdateValue<TClass> | public void UpdateValue<TClass>(string key, object value) where TClass : ConfigurationLoader, new() | Updates a single key in TClass’s .ini section, persists it to disk, and reloads TClass. |
ReloadAll | public void ReloadAll() | Re-reads the active .ini file and updates all cached instances in-place (throws TimeoutException if another reload is concurrently running). |
Flush | public void Flush() | Writes any buffered .ini defaults/comments to disk. |
IsLoaded<TClass>() | public bool IsLoaded<TClass>() where TClass : ConfigurationLoader | Returns true if TClass is currently cached. |
Remove<TClass>() | public bool Remove<TClass>() where TClass : ConfigurationLoader | Removes TClass from the active cache. |
ClearAll | public void ClearAll() | Clears all cached configuration instances. |
ConfigurationLoader
All option classes inherit from ConfigurationLoader (Clone<T>() where T : ConfigurationLoader, new()) and must be declared partial so ConfigurationGenerator can emit BindProperties, CopyPropertiesTo, CloneEmpty, and ValidateDataAnnotations.
Section Naming Convention
The .ini section name is derived by stripping standard suffixes (Options, Config, Settings, Option, Configs, Setting, Configuration, Configurations) from the class name:
NetworkSocketOptions$\rightarrow$[NetworkSocket]TransportOptions$\rightarrow$[Transport]
Supported Property Types (IniConfig)
IniConfig and ConfigurationGenerator support:
- Integers & Bytes:
byte,sbyte,short,ushort,int,uint,long,ulong(GetByte,GetSByte,GetInt16,GetUInt16,GetInt32,GetUInt32,GetInt64,GetUInt64) - Floating-Point & Decimal:
float(GetSingle),double(GetDouble),decimal(GetDecimal) - Primitives & Value Types:
bool(GetBool),char(GetChar),string(GetString),TimeSpan(GetTimeSpan),DateTime(GetDateTime),Guid(GetGuid), andenum(GetEnum<TEnum>).
using Nalix.Abstractions;
using Nalix.Abstractions.Validation;
using Nalix.Environment.Configuration.Binding;
[IniComment("Server room settings")]
public sealed partial class ServerRoomOptions : ConfigurationLoader, IValidatableConfiguration
{
[IniComment("Listen port (1..65535)")]
[ValueRange(1, 65535)]
public ushort Port { get; set; } = 57206;
[ConfiguredIgnore]
public string InternalRuntimeId { get; set; } = "local";
public void Validate() => this.ValidateDataAnnotations();
}