Config
Config<T> is the framework’s typed configuration abstraction for JSON, XML, and .config-style settings. It loads configuration into strongly typed C# objects from files, appsettings.json, or Azure Key Vault.
Features
- Auto-discovery: locates files by class name in
~/,~/Configs/, and~/Configurations/. - Environment transforms: supports
ClassName.Environment.jsonoverrides. - Decryption: decrypts encrypted properties using
ConfigDecryptAttribute. - AppSettings support: loads configuration from named sections in
appsettings.json. - Environment variables: supports environment-specific overrides.
- Key Vault support: loads configuration and environment transforms from Azure Key Vault.
Behavior
Configuration is loaded lazily on first access to T.Current and cached for the lifetime of the application.
Files are discovered by class name using case-insensitive matching. Environment-specific transforms are applied on top of the base configuration when available.
When Key Vault is configured through systemLibraryCommonFramework:config:keyVaultUrl, the framework can load:
{groupName}.json{groupName}.{Environment}.json
These are applied as configuration values and environment transforms. Dots in secret names are replaced with hyphens to comply with Key Vault naming restrictions.
Environment-variable overrides use the following prefixes:
APP_for configuration files outsideappsettings.json.APP_,ASPNETCORE_, andDOTNET_forappsettings.json.
Decryption
Properties decorated with ConfigDecryptAttribute are decrypted during configuration loading.
public class PokemonConfig : Config<PokemonConfig>
{
public string Token { get; set; }
[ConfigDecrypt("Token")]
public string TokenDecrypted { get; set; }
}
Values must be encrypted using the framework's string.Encrypt() method so the same default key is used during decryption.
Example
public class PokemonConfig : Config<PokemonConfig>
{
public string Url { get; set; }
public int CacheDuration { get; set; }
}
var url = PokemonConfig.Current.Url;
Example configuration files:
PokemonConfig.jsonPokemonConfig.Production.jsonPokemonConfig.Development.json
Caveats
Tcannot be a nested type.- The configuration file must exist and cannot be empty.
- Decryption failures throw exceptions.
- Key Vault retrieval failures are logged as warnings, and startup continues without the unavailable values.
Tip
Encrypted values can be stored alongside source code, as long as the encryption key is kept separate.