Skip to content

Environment Variables ​

Environment variables configuration source, included in the core package.

Default Level ​

The default level for this configuration source is CfgSourceLevels.EnvironmentVariables (400).

If you don't specify the level parameter, the default level will be used:

csharp
// Uses default level 400
.AddEnvironmentVariables(prefix: "APP_")

// Specify custom level
.AddEnvironmentVariables(prefix: "APP_", level: 450)

Basic Usage ​

csharp
using Apq.Cfg;

var cfg = new CfgBuilder()
    .AddEnvironmentVariables(prefix: "APP_")  // Uses default level 400
    .Build();

Prefix Filtering ​

Use prefix to filter relevant variables:

bash
# These will be included with prefix "APP_"
APP_NAME=MyApp
APP_PORT=8080
APP_DATABASE__HOST=localhost

# These will be excluded
OTHER_VAR=value

Key Mapping ​

Environment variables use double underscore for hierarchy:

Environment VariableConfiguration Key
APP_NAMEName
APP_DATABASE__HOSTDatabase:Host
APP_DATABASE__PORTDatabase:Port

Priority ​

Environment variables have the highest default priority (level 400) to allow runtime overrides.

Next Steps ​

Released under the MIT License