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 Type | Default Level |
|---|---|
| Json, Ini, Xml, Yaml, Toml | 0 |
| Redis, Database | 100 |
| Consul, Etcd, Nacos, Apollo, Zookeeper | 200 |
| Vault | 300 |
| .env, EnvironmentVariables | 400 |
Local Configuration Sources
| Source | Package | Default Level | Description |
|---|---|---|---|
| JSON | Apq.Cfg | 0 | JSON file configuration |
| YAML | Apq.Cfg.Yaml | 0 | YAML file configuration |
| XML | Apq.Cfg.Xml | 0 | XML file configuration |
| INI | Apq.Cfg.Ini | 0 | INI file configuration |
| TOML | Apq.Cfg.Toml | 0 | TOML file configuration |
| .env | Apq.Cfg.Env | 400 | .env file configuration |
| Environment Variables | Apq.Cfg | 400 | Environment variables |
Remote Configuration Sources
| Source | Package | Default Level | Description |
|---|---|---|---|
| Redis | Apq.Cfg.Redis | 100 | Redis key-value store |
| Database | Apq.Cfg.Database | 100 | Database configuration |
| Consul | Apq.Cfg.Consul | 200 | HashiCorp Consul |
| Etcd | Apq.Cfg.Etcd | 200 | Etcd key-value store |
| Nacos | Apq.Cfg.Nacos | 200 | Alibaba Nacos |
| Apollo | Apq.Cfg.Apollo | 200 | Ctrip Apollo |
| Zookeeper | Apq.Cfg.Zookeeper | 200 | Apache Zookeeper |
| Vault | Apq.Cfg.Vault | 300 | HashiCorp 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: