Skip to content

Apq.Cfg高性能 .NET 配置管理库

支持多种配置源、动态重载、依赖注入集成

Apq.Cfg

快速安装

bash
# 安装核心包
dotnet add package Apq.Cfg

# 安装 YAML 支持
dotnet add package Apq.Cfg.Yaml

# 安装 Consul 支持
dotnet add package Apq.Cfg.Consul
xml
<PackageReference Include="Apq.Cfg" Version="1.0.*" />
<PackageReference Include="Apq.Cfg.Yaml" Version="1.0.*" />
<PackageReference Include="Apq.Cfg.Consul" Version="1.0.*" />

简单示例

csharp
using Apq.Cfg;

// 创建配置
var cfg = new CfgBuilder()
    .AddJsonFile("config.json")
    .AddYamlFile("config.yaml", optional: true)
    .AddEnvironmentVariables()
    .Build();

// 读取配置
var connectionString = cfg["Database:ConnectionString"];
var timeout = cfg.GetValue<int>("Database:Timeout");

// 绑定到强类型对象
var dbConfig = cfg.GetSection("Database").Get<DatabaseConfig>();

支持的配置源

类型配置源NuGet 包
本地JSONApq.Cfg (内置)
本地YAMLApq.Cfg.Yaml
本地XMLApq.Cfg.Xml
本地INIApq.Cfg.Ini
本地TOMLApq.Cfg.Toml
本地环境变量Apq.Cfg (内置)
远程ConsulApq.Cfg.Consul
远程RedisApq.Cfg.Redis
远程ApolloApq.Cfg.Apollo
远程VaultApq.Cfg.Vault
远程EtcdApq.Cfg.Etcd
远程ZookeeperApq.Cfg.Zookeeper
远程NacosApq.Cfg.Nacos

基于 MIT 许可发布