Skip to content

Source Selection ​

This guide helps you choose the right configuration sources for your application.

Decision Guide ​

Local vs Remote ​

ScenarioRecommended Source
Single applicationLocal files (JSON, YAML)
MicroservicesRemote (Consul, Nacos)
Secrets managementVault
Container deploymentEnvironment variables + Remote

File Format Selection ​

FormatBest For
JSONMost applications, good tooling support
YAMLComplex hierarchies, human-readable
TOMLSimple configs, Rust ecosystem
INILegacy systems, simple key-value
XMLEnterprise systems, schema validation

Common Patterns ​

Development Environment ​

csharp
var cfg = new CfgBuilder()
    .AddJsonFile("config.json", level: 0, writeable: false)
    .AddJsonFile("config.Development.json", level: 1, writeable: false, optional: true)
    .AddJsonFile("config.local.json", level: 2, writeable: true, optional: true)
    .Build();

Production with Remote Config ​

csharp
var cfg = new CfgBuilder()
    .AddJsonFile("config.json", level: 0, writeable: false)
    .AddConsul(options =>
    {
        options.Address = "http://consul:8500";
        options.KeyPrefix = "myapp/config/";
    }, level: 10, writeable: true, reloadOnChange: true)
    .AddVault(options =>
    {
        options.Address = "http://vault:8200";
        options.SecretPath = "secret/myapp";
    }, level: 15, writeable: false)
    .AddEnvironmentVariables(level: 20, prefix: "MYAPP_")
    .Build();

Kubernetes Deployment ​

csharp
var cfg = new CfgBuilder()
    .AddJsonFile("/app/config/config.json", level: 0, writeable: false)
    .AddJsonFile("/app/secrets/secrets.json", level: 5, writeable: false, optional: true)
    .AddEnvironmentVariables(level: 10, prefix: "APP_")
    .Build();

Level Guidelines ​

Level RangePurposeExamples
0-9Base configurationconfig.json, config.yaml
10-19Remote configurationConsul, Nacos, Etcd
15-19SecretsVault
20+OverridesEnvironment variables

Next Steps ​

Released under the MIT License