JinYi.Extensions.Configuration.RemoteJson
1.0.4
dotnet add package JinYi.Extensions.Configuration.RemoteJson --version 1.0.4
NuGet\Install-Package JinYi.Extensions.Configuration.RemoteJson -Version 1.0.4
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="JinYi.Extensions.Configuration.RemoteJson" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JinYi.Extensions.Configuration.RemoteJson" Version="1.0.4" />
<PackageReference Include="JinYi.Extensions.Configuration.RemoteJson" />
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 JinYi.Extensions.Configuration.RemoteJson --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JinYi.Extensions.Configuration.RemoteJson, 1.0.4"
#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 JinYi.Extensions.Configuration.RemoteJson@1.0.4
#: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=JinYi.Extensions.Configuration.RemoteJson&version=1.0.4
#tool nuget:?package=JinYi.Extensions.Configuration.RemoteJson&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JinYi.Extensions.Configuration.RemoteJson
一个可复用的远程配置提供者,支持从远程 HTTP JSON 拉取配置并合并到应用 IConfiguration 中,支持定时热更新,且遵循 appsettings*.json 的解析规则(对象用冒号 : 连接、数组用索引展开、忽略 null/undefined)。
功能
- 通过
RemoteJsonConfigurationProvider异步获取远程 JSON 配置。 - 使用
SocketsHttpHandler/持久化HttpClient复用连接,避免频繁释放带来的 DNS/连接问题。 - 通过
ReloadSeconds配置定时刷新,调用OnReload()推送变更。 - 使用
ETag/Last-Modified条件请求,返回 304 时跳过解析以降低开销。 - 与本地
appsettings*.json解析行为对齐:键扁平化、大小写不敏感、标量使用不变区域性。
安装
快速开始
在本地
appsettings.json或分环境文件中配置远程地址与刷新间隔:在
Program.cs注册远程配置提供者(封装读取本地配置项):使用选项模式绑定你的配置:
API 说明
RemoteJsonConfigurationExtensions.AddRemoteJson(IConfiguration config, HttpMessageHandler? handler = null)- 读取
RemoteConfig:Endpoint与RemoteConfig:ReloadSeconds,注册远程配置提供者。
- 读取
- 提供者内部:
Load()首次同步填充,后续通过Timer异步刷新。FetchRemoteDataAsync()使用If-None-Match/If-Modified-Since发起条件 GET,请求成功返回 200 时解析;304 时不触发重载。
与 Kubernetes/云原生的配合
- 可将远程
appsettings*.json放置在对象存储或配置中心,配合就绪/存活/启动探针实现稳定发布:/health/live存活、/health/startup启动、/health/ready就绪。POST /prestop触发 Drain,使就绪失败以实现优雅摘流。
注意事项
- 远端 JSON 结构需与本地键一致,便于覆盖。
- 如需认证,在构造
HttpMessageHandler时添加认证头或令牌。 ReloadSeconds建议大于 5 秒,避免高频刷新。- 远端不可达时不影响启动(保留本地配置);如需强制失败,可在
Load()首次拉取失败时抛出异常。
配置示例(远端 JSON)
许可
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.