🚀
高性能
基于值缓存和快速集合优化,提供卓越的配置读取性能,支持高并发场景
# 安装核心包
dotnet add package Apq.Cfg
# 安装 YAML 支持
dotnet add package Apq.Cfg.Yaml
# 安装 Consul 支持
dotnet add package Apq.Cfg.Consul<PackageReference Include="Apq.Cfg" Version="1.1.*" />
<PackageReference Include="Apq.Cfg.Yaml" Version="1.1.*" />
<PackageReference Include="Apq.Cfg.Consul" Version="1.1.*" />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").GetValue<DatabaseConfig>();| 类型 | 配置源 | NuGet 包 |
|---|---|---|
| 本地 | JSON | Apq.Cfg (内置) |
| 本地 | YAML | Apq.Cfg.Yaml |
| 本地 | XML | Apq.Cfg.Xml |
| 本地 | INI | Apq.Cfg.Ini |
| 本地 | TOML | Apq.Cfg.Toml |
| 本地 | .env 文件 | Apq.Cfg.Env |
| 本地 | 环境变量 | Apq.Cfg (内置) |
| 数据存储 | Redis | Apq.Cfg.Redis |
| 数据存储 | Database | Apq.Cfg.Database |
| 配置中心 | Consul | Apq.Cfg.Consul |
| 配置中心 | Apollo | Apq.Cfg.Apollo |
| 配置中心 | Nacos | Apq.Cfg.Nacos |
| 配置中心 | Vault | Apq.Cfg.Vault |
| 配置中心 | Etcd | Apq.Cfg.Etcd |
| 配置中心 | Zookeeper | Apq.Cfg.Zookeeper |
| 功能 | 说明 | NuGet 包 |
|---|---|---|
| 加密脱敏 | AES-GCM/AES-CBC/ChaCha20/SM4/3DES 加密,敏感字段脱敏 | Apq.Cfg.Crypto |
| Data Protection | ASP.NET Core Data Protection 集成 | Apq.Cfg.Crypto.DataProtection |
| 加密工具 | 命令行加密工具 (dotnet tool) | Apq.Cfg.Crypto.Tool |
| 源生成器 | 编译时生成零反射绑定代码,支持 Native AOT | Apq.Cfg.SourceGenerator |
| Web API | RESTful API 接口,支持远程配置管理 | Apq.Cfg.WebApi |
| Web 管理界面 | 集中管理多个应用的配置 | Apq.Cfg.WebUI |