Cyoukon.Extensions.Configuration.Abstractions
1.0.0
dotnet add package Cyoukon.Extensions.Configuration.Abstractions --version 1.0.0
NuGet\Install-Package Cyoukon.Extensions.Configuration.Abstractions -Version 1.0.0
<PackageReference Include="Cyoukon.Extensions.Configuration.Abstractions" Version="1.0.0" />
<PackageVersion Include="Cyoukon.Extensions.Configuration.Abstractions" Version="1.0.0" />
<PackageReference Include="Cyoukon.Extensions.Configuration.Abstractions" />
paket add Cyoukon.Extensions.Configuration.Abstractions --version 1.0.0
#r "nuget: Cyoukon.Extensions.Configuration.Abstractions, 1.0.0"
#:package Cyoukon.Extensions.Configuration.Abstractions@1.0.0
#addin nuget:?package=Cyoukon.Extensions.Configuration.Abstractions&version=1.0.0
#tool nuget:?package=Cyoukon.Extensions.Configuration.Abstractions&version=1.0.0
Cyoukon.Extensions.Configuration.Abstractions
共享抽象层,为 Git 仓库配置提供程序(GitHub、Gitee)提供基础类和接口。
功能特性
- 📦 GitConfigurationProviderBase - Git 配置提供程序基类,封装了配置加载、保存、自动重载等核心逻辑
- 🔐 IEncryptionService - 加密服务接口
- 🔒 AesEncryptionService - AES-256 加密服务实现
- ⚙️ GitRepositoryOptions - Git 仓库配置选项基类
- 🔔 WebhookResult - Webhook 处理结果模型
- 🛡️ WebhookSignatureVerifier - Webhook 签名验证工具
安装
dotnet add package Cyoukon.Extensions.Configuration.Abstractions
核心类
GitConfigurationProviderBase<TOptions>
Git 配置提供程序的抽象基类:
public abstract class GitConfigurationProviderBase<TOptions> : ConfigurationProvider, IDisposable
where TOptions : GitRepositoryOptions
{
// 加载配置
protected abstract Task LoadAsync();
// 保存配置
public abstract Task<bool> SaveAsync(Dictionary<string, string?> data, string commitMessage);
// 设置单个配置项
public async Task<bool> SetAsync(string key, string? value, string commitMessage);
// 删除配置项
public async Task<bool> RemoveAsync(string key, string commitMessage);
// 重新加载
public void Reload();
// 处理 Webhook
public void OnWebhookReceived();
}
GitRepositoryOptions
Git 仓库配置选项基类:
public abstract class GitRepositoryOptions
{
public string AccessToken { get; set; }
public string Owner { get; set; }
public string Repo { get; set; }
public string Branch { get; set; } = "main";
public string ConfigPath { get; set; } = "config";
public string ConfigFileName { get; set; } = "appsettings.json";
public bool EnableEncryption { get; set; }
public string? EncryptionKey { get; set; }
public bool EnableReload { get; set; }
public TimeSpan ReloadInterval { get; set; } = TimeSpan.FromMinutes(5);
public string? WebhookSecret { get; set; }
public virtual void Validate();
}
IEncryptionService
加密服务接口:
public interface IEncryptionService
{
string Encrypt(string plainText);
string Decrypt(string cipherText);
}
AesEncryptionService
AES-256 加密服务实现:
var encryptionService = new AesEncryptionService("your-secret-key");
var encrypted = encryptionService.Encrypt("plain text");
var decrypted = encryptionService.Decrypt(encrypted);
WebhookResult
Webhook 处理结果:
public class WebhookResult
{
public bool Success { get; set; }
public string? Message { get; set; }
public bool ConfigurationChanged { get; set; }
public string[]? ChangedFiles { get; set; }
}
实现自定义配置提供程序
继承 GitConfigurationProviderBase 实现自定义 Git 平台配置提供程序:
public class MyGitConfigurationProvider : GitConfigurationProviderBase<MyGitOptions>
{
private readonly IMyGitApiClient _apiClient;
public MyGitConfigurationProvider(MyGitOptions options, IMyGitApiClient apiClient)
: base(options, null)
{
_apiClient = apiClient;
}
protected override async Task LoadAsync()
{
var content = await _apiClient.GetFileContentAsync(
Options.Owner,
Options.Repo,
Options.GetFilePath(),
Options.Branch);
content = ProcessContentBeforeLoad(content);
var data = ConfigurationParser.ParseJson(content);
SetData(data, true);
}
public override async Task<bool> SaveAsync(Dictionary<string, string?> data, string commitMessage)
{
var json = ConfigurationParser.ToJson(data);
json = ProcessContentBeforeSave(json);
return await _apiClient.UpdateFileAsync(
Options.Owner,
Options.Repo,
Options.GetFilePath(),
json,
commitMessage,
Options.Branch);
}
}
相关项目
- Cyoukon.Extensions.Configuration.Github - GitHub 配置提供程序
- Cyoukon.Extensions.Configuration.Gitee - Gitee 配置提供程序
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.1)
- System.Text.Json (>= 10.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Cyoukon.Extensions.Configuration.Abstractions:
| Package | Downloads |
|---|---|
|
Cyoukon.Extensions.Configuration.Github
GitHub configuration provider for Microsoft.Extensions.Configuration. Supports remote configuration from GitHub repositories with webhook-based hot reload. |
|
|
Cyoukon.Extensions.Configuration.Gitee
Gitee configuration provider for Microsoft.Extensions.Configuration. Supports remote configuration from Gitee repositories with webhook-based hot reload. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 198 | 3/19/2026 |