Skip to content

Config Sources Overview

Apq.Cfg supports 14+ configuration sources, divided into local and remote categories.

Default Levels

Each configuration source has a default level. If not specified, the default level is used:

Source TypeDefault Level
Json, Ini, Xml, Yaml, Toml0
Redis, Database100
Consul, Etcd, Nacos, Apollo, Zookeeper200
Vault300
.env, EnvironmentVariables400

Local Configuration Sources

SourcePackageDefault LevelDescription
JSONApq.Cfg0JSON file configuration
YAMLApq.Cfg.Yaml0YAML file configuration
XMLApq.Cfg.Xml0XML file configuration
INIApq.Cfg.Ini0INI file configuration
TOMLApq.Cfg.Toml0TOML file configuration
.envApq.Cfg.Env400.env file configuration
Environment VariablesApq.Cfg400Environment variables

Remote Configuration Sources

SourcePackageDefault LevelDescription
RedisApq.Cfg.Redis100Redis key-value store
DatabaseApq.Cfg.Database100Database configuration
ConsulApq.Cfg.Consul200HashiCorp Consul
EtcdApq.Cfg.Etcd200Etcd key-value store
NacosApq.Cfg.Nacos200Alibaba Nacos
ApolloApq.Cfg.Apollo200Ctrip Apollo
ZookeeperApq.Cfg.Zookeeper200Apache Zookeeper
VaultApq.Cfg.Vault300HashiCorp Vault

Quick Example

csharp
using Apq.Cfg;

var cfg = new CfgBuilder()
    // Local sources (uses default level 0)
    .AddJsonFile("config.json")
    .AddYamlFile("config.yaml", level: 10, optional: true)

    // Remote sources (uses default level 200)
    .AddConsul(options =>
    {
        options.Address = "http://localhost:8500";
        options.KeyPrefix = "app/config/";
    }, writeable: true)

    // Environment variables (uses default level 400)
    .AddEnvironmentVariables(prefix: "APP_")
    .Build();

Level Priority

Configuration sources are merged by level, higher levels override lower levels:

Level 0:   config.json          (base configuration)
Level 10:  config.{env}.json    (environment-specific)
Level 50:  config.local.json    (local overrides)
Level 100: Redis/Database       (remote storage)
Level 200: Consul/Nacos/Etcd    (config centers)
Level 300: Vault                (secrets)
Level 400: Environment Variables (highest priority)

Next Steps

Choose a configuration source to learn more:

  • JSON - Most common format
  • YAML - Human-readable format
  • Consul - Service discovery and configuration
  • Vault - Secrets management

Released under the MIT License