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" />
                    
Directory.Packages.props
<PackageReference Include="JinYi.Extensions.Configuration.RemoteJson" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=JinYi.Extensions.Configuration.RemoteJson&version=1.0.4
                    
Install as a Cake Tool

JinYi.Extensions.Configuration.RemoteJson

一个可复用的远程配置提供者,支持从远程 HTTP JSON 拉取配置并合并到应用 IConfiguration 中,支持定时热更新,且遵循 appsettings*.json 的解析规则(对象用冒号 : 连接、数组用索引展开、忽略 null/undefined)。

功能

  • 通过 RemoteJsonConfigurationProvider 异步获取远程 JSON 配置。
  • 使用 SocketsHttpHandler/持久化 HttpClient 复用连接,避免频繁释放带来的 DNS/连接问题。
  • 通过 ReloadSeconds 配置定时刷新,调用 OnReload() 推送变更。
  • 使用 ETag/Last-Modified 条件请求,返回 304 时跳过解析以降低开销。
  • 与本地 appsettings*.json 解析行为对齐:键扁平化、大小写不敏感、标量使用不变区域性。

安装

快速开始

  1. 在本地 appsettings.json 或分环境文件中配置远程地址与刷新间隔:

  2. 在 Program.cs 注册远程配置提供者(封装读取本地配置项):

  3. 使用选项模式绑定你的配置:

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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 408 11/30/2025
1.0.3 392 11/30/2025
1.0.2 279 11/30/2025
1.0.1 271 11/30/2025
1.0.0 306 11/30/2025