Apq.Cfg
1.2.1
dotnet add package Apq.Cfg --version 1.2.1
NuGet\Install-Package Apq.Cfg -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Apq.Cfg" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Apq.Cfg" Version="1.2.1" />
<PackageReference Include="Apq.Cfg" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Apq.Cfg --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Apq.Cfg, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Apq.Cfg@1.2.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Apq.Cfg&version=1.2.1
#tool nuget:?package=Apq.Cfg&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Apq.Cfg
.NET 统一配置组件库核心包,提供配置管理接口和基础实现。
📖 在线文档:https://apq-cfg.vercel.app/
安装
dotnet add package Apq.Cfg
快速开始
using Apq.Cfg;
// 构建配置
var cfg = new CfgBuilder()
.AddJsonFile("config.json")
.AddJsonFile("config.local.json", level: 1, writeable: true, isPrimaryWriter: true)
.Build();
// 读取配置
var host = cfg["Database:Host"];
var port = cfg.GetValue<int>("Database:Port");
// 使用配置节
var db = cfg.GetSection("Database");
var name = db["Name"];
// 修改并保存
cfg["App:LastRun"] = DateTime.Now.ToString();
await cfg.SaveAsync();
核心接口
ICfgRoot
public interface ICfgRoot : IDisposable, IAsyncDisposable
{
string? this[string key] { get; set; }
T? GetValue<T>(string key);
bool Exists(string key);
ICfgSection GetSection(string path);
void SetValue(string key, string? value, int? targetLevel = null);
void Remove(string key, int? targetLevel = null);
Task SaveAsync(int? targetLevel = null, CancellationToken ct = default);
IObservable<ConfigChangeEvent> ConfigChanges { get; }
}
ICfgSection
public interface ICfgSection
{
string? this[string key] { get; set; }
string Path { get; }
T? GetValue<T>(string key);
bool Exists(string key);
void SetValue(string key, string? value, int? targetLevel = null);
void Remove(string key, int? targetLevel = null);
ICfgSection GetSection(string path);
}
配置层级
| 层级 | 用途 | 配置源 |
|---|---|---|
| 0-99 | 本地文件 | Json, Ini, Xml, Yaml, Toml, Hcl, Properties |
| 100-199 | 远程存储 | Redis, Database |
| 200-299 | 配置中心 | Consul, Etcd, Nacos, Apollo, Zookeeper |
| 300-399 | 密钥管理 | Vault |
| 400+ | 环境变量 | Env, EnvironmentVariables |
扩展包
| 包名 | 说明 |
|---|---|
Apq.Cfg.Ini |
INI 格式 |
Apq.Cfg.Xml |
XML 格式 |
Apq.Cfg.Yaml |
YAML 格式 |
Apq.Cfg.Toml |
TOML 格式 |
Apq.Cfg.Hcl |
HOCON 格式 (Akka/Play Framework) |
Apq.Cfg.Properties |
Java Properties 格式 |
Apq.Cfg.Env |
.env 文件 |
Apq.Cfg.Redis |
Redis 存储 |
Apq.Cfg.Database |
数据库存储 |
Apq.Cfg.Consul |
Consul 配置中心 |
Apq.Cfg.Etcd |
Etcd 配置中心 |
Apq.Cfg.Nacos |
Nacos 配置中心 |
Apq.Cfg.Apollo |
Apollo 配置中心 |
Apq.Cfg.Zookeeper |
Zookeeper 配置中心 |
Apq.Cfg.Vault |
HashiCorp Vault |
Apq.Cfg.Crypto |
配置加密脱敏 |
Apq.Cfg.SourceGenerator |
源生成器 (Native AOT) |
许可证
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.1)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.1)
- Microsoft.Extensions.Configuration.Json (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Options (>= 10.0.1)
- System.Reactive (>= 6.1.0)
- UTF.Unknown (>= 2.6.0)
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- System.Reactive (>= 6.1.0)
- UTF.Unknown (>= 2.6.0)
NuGet packages (17)
Showing the top 5 NuGet packages that depend on Apq.Cfg:
| Package | Downloads |
|---|---|
|
Apq.Cfg.Ini
Apq.Cfg 的 INI 文件配置源扩展 |
|
|
Apq.Cfg.Yaml
Apq.Cfg 的 YAML 文件配置源扩展 |
|
|
Apq.Cfg.Redis
Apq.Cfg 的 Redis 配置源扩展 |
|
|
Apq.Cfg.Toml
Apq.Cfg 的 TOML 文件配置源扩展 |
|
|
Apq.Cfg.Xml
Apq.Cfg 的 XML 文件配置源扩展 |
GitHub repositories
This package is not used by any popular GitHub repositories.