Galosys.Foundation.NacosConfig
26.5.20.1
dotnet add package Galosys.Foundation.NacosConfig --version 26.5.20.1
NuGet\Install-Package Galosys.Foundation.NacosConfig -Version 26.5.20.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="Galosys.Foundation.NacosConfig" Version="26.5.20.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.NacosConfig" Version="26.5.20.1" />
<PackageReference Include="Galosys.Foundation.NacosConfig" />
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 Galosys.Foundation.NacosConfig --version 26.5.20.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.NacosConfig, 26.5.20.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 Galosys.Foundation.NacosConfig@26.5.20.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=Galosys.Foundation.NacosConfig&version=26.5.20.1
#tool nuget:?package=Galosys.Foundation.NacosConfig&version=26.5.20.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.NacosConfig
成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善
Galosys.Foundation Nacos 配置中心集成模块,提供 Nacos 配置服务、动态配置监听、健康检查指示器等功能。
功能概览
1. Nacos 配置服务集成
// 自动注册 Nacos 配置服务
services.AddNacosV2Config(opt =>
{
opt.ConfigUseRpc = false;
opt.ServerAddresses = serverAddresses;
opt.Namespace = environment;
opt.UserName = userName;
opt.Password = password;
});
2. 动态配置监听
// 配置监听器自动监听 appsettings.json 变更
builder.UseNacosConfig();
3. 健康检查指示器
// Nacos 配置健康检查指示器
public class NacosConfigIndicatorProvider : IIndicatorProvider
{
public string Name => "nacos.config";
public async Task<object> ParasAsync()
{
// 获取 Nacos 配置状态
var config = await nacosConfig.GetConfig("appsettings.json", group, 3000);
return config ?? "未配置";
}
}
安装
<PackageReference Include="Galosys.Foundation.NacosConfig" Version="x.x.x" />
使用
配置 Nacos 服务
// 在 appsettings.json 中配置
{
"Nacos": {
"ServerAddr": [ "http://localhost:60013/" ],
"UserName": "nacos",
"Password": "nacos",
"AccessKey": "",
"SecretKey": "",
"Endpoint": ""
}
}
启用 Nacos 配置
// 在 Program.cs 中
builder.Host.UseNacosConfig();
// 或使用自定义解析器
builder.Host.UseNacosConfig(parser, logAction);
使用配置服务
// 注入 Nacos 配置服务
public class MyService
{
private readonly INacosConfigService _nacosConfig;
public MyService(INacosConfigService nacosConfig)
{
_nacosConfig = nacosConfig;
}
public async Task<string> GetConfigAsync()
{
return await _nacosConfig.GetConfig("appsettings.json", "DEFAULT_GROUP", 3000);
}
}
环境隔离
// 自动根据环境变量设置命名空间
opt.Namespace = Env.GetEnvironment(); // Development, Production 等
// 应用名称作为配置组名
Group = Env.GetApplicationName();
核心类
| 分类 | 类 | 说明 |
|---|---|---|
| 模块 | NacosConfigModule |
Nacos 配置模块主类 |
| 配置 | NacosConfigOptions |
Nacos 配置选项 |
| 指示器 | NacosConfigIndicatorProvider |
配置健康检查指示器 |
| 扩展 | NacosConfigHostBuilderExtensions |
主机构建器扩展 |
目录结构
Galosys.Foundation.NacosConfig/
├── Microsoft/
│ └── Extensions/
│ └── Hosting/
│ └── NacosConfigHostBuilderExtensions.cs # 主机扩展方法
├── NacosConfigModule.cs # 模块主类
└── NacosConfigIndicatorProvider.cs # 健康检查指示器
配置选项
| 配置项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| ServerAddr | List<string> | [] | Nacos 服务器地址列表 |
| UserName | string? | null | 用户名 |
| Password | string? | null | 密码 |
| AccessKey | string? | null | 访问密钥 |
| SecretKey | string? | null | 密钥 |
| Endpoint | string? | null | 端点地址 |
依赖
- nacos-sdk-csharp.extensions.configuration
- Galosys.Foundation.Core
注意事项
- 环境隔离:模块自动根据
ASPNETCORE_ENVIRONMENT设置 Nacos 命名空间 - 配置监听:默认监听
appsettings.json文件变更 - RPC 配置:默认禁用 RPC,使用 HTTP 协议
- 安全配置:生产环境应使用 AccessKey/SecretKey 认证
- 健康检查:通过
IIndicatorProvider接口提供配置状态监控
| 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 was computed. 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.
-
net8.0
- Galosys.Foundation.Core (>= 26.5.20.1)
- nacos-sdk-csharp.extensions.configuration (>= 1.3.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Galosys.Foundation.NacosConfig:
| Package | Downloads |
|---|---|
|
Galosys.Micro.App
Galosys.Foundation快速开发库 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 26.5.20.1 | 96 | 5/20/2026 |
| 26.5.19.1 | 97 | 5/19/2026 |
| 26.5.18.1 | 97 | 5/18/2026 |
| 26.5.15.1 | 94 | 5/15/2026 |
| 26.5.12.3 | 96 | 5/12/2026 |
| 26.5.12.2 | 100 | 5/12/2026 |
| 26.4.27.1-rc1 | 98 | 4/26/2026 |
| 26.4.25.1-rc1 | 89 | 4/25/2026 |
| 26.4.22.2-rc7 | 91 | 4/22/2026 |
| 26.4.22.2-rc6 | 91 | 4/22/2026 |
| 26.4.22.2-rc4 | 90 | 4/22/2026 |
| 26.4.22.2-rc3 | 89 | 4/22/2026 |
| 26.4.19.1-rc1 | 96 | 4/19/2026 |
| 26.4.12.8-rc1 | 98 | 4/12/2026 |
| 26.4.12.7-rc1 | 94 | 4/12/2026 |
| 26.4.12.5-rc1 | 93 | 4/12/2026 |
| 26.1.30.1-rc1 | 126 | 1/30/2026 |
| 26.1.29.1 | 139 | 1/29/2026 |
| 26.1.28.5 | 123 | 1/28/2026 |
| 26.1.28.4 | 128 | 1/28/2026 |
Loading failed