WormDb.Extensions
1.0.4
dotnet add package WormDb.Extensions --version 1.0.4
NuGet\Install-Package WormDb.Extensions -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="WormDb.Extensions" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WormDb.Extensions" Version="1.0.4" />
<PackageReference Include="WormDb.Extensions" />
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 WormDb.Extensions --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: WormDb.Extensions, 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 WormDb.Extensions@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=WormDb.Extensions&version=1.0.4
#tool nuget:?package=WormDb.Extensions&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
WormDb.Extensions
WormDb 的 ASP.NET Core 扩展包,提供
AddWormDb()和MapWormDbHttpApi()两条扩展方法,一行代码将 WormDb 集成到现有 Web 应用中。支持 Standalone / Leader / Follower 三种模式,自动处理生命周期(启动、停止、优雅退出)。
功能
| 特性 | 说明 |
|---|---|
| DI 原生集成 | services.AddWormDb() 注册所有服务(单例) |
| 配置绑定 | 支持 appsettings.json 配置节点或代码配置 |
| 端点自动映射 | app.MapWormDbHttpApi() 自动注册所有 REST 端点 |
| 模式感知 | Leader 模式只读,Follower/Standalone 可读写 |
| 生命周期托管 | IHostedService 自动处理启动/停止/优雅退出 |
| NuGet 包 | 发布为 WormDb NuGet 包,安装即用 |
核心 API
DI 注册
// 从 appsettings.json 配置
services.AddWormDb(configuration.GetSection("WormDb"));
// 或代码配置
services.AddWormDb(opts =>
{
opts.Mode = WormDbMode.Standalone;
opts.DataDir = "./data";
opts.SegMaxBytes = 256 * 1024 * 1024;
opts.TagIndexKeys = new[] { "level", "service" };
});
端点映射
// WebApplication 上
app.MapWormDbHttpApi();
// 或 IEndpointRouteBuilder 上
endpoints.MapWormDbHttpApi();
DI 可获取的服务
| 服务 | 说明 |
|---|---|
ILogDatabase / LogDatabase |
日志数据库实例(单例) |
LeaderNode |
Leader 节点(仅 Leader 模式非空) |
FollowerReplicationClient |
Follower 客户端(仅 Follower 模式非空) |
IOptions<WormDbOptions> |
配置快照 |
HTTP REST API
| 端点 | 方法 | Standalone | Leader | Follower |
|---|---|---|---|---|
/api/entries |
POST | 写入 | 403 | 写入 + 推流 |
/api/entries/batch |
POST | 批量写入 | 403 | 写入 + 推流 |
/api/entries |
GET | 查询 | 查询 | 查询 |
/api/entries/paged |
GET | 分页 | 分页 | 分页 |
/api/entries/latest |
GET | 最新 | 最新 | 最新 |
/api/stats |
GET | 节点统计 | 汇聚统计 | 节点 + 推流统计 |
/api/health |
GET | 健康检查 | 健康检查 | 健康检查 |
/api/shutdown |
POST | - | - | 优雅退出 |
配置
appsettings.json
{
"WormDb": {
"Mode": "standalone",
"DataDir": "./data",
"SegMaxBytes": 268435456,
"WriteQueueCapacity": 65536,
"TagIndexKeys": ["level", "service"],
"NodeId": 0,
"LeaderAddress": null,
"GrpcPort": 5100
}
}
配置选项
public class WormDbOptions
{
public WormDbMode Mode { get; set; } // Standalone | Leader | Follower
public string DataDir { get; set; } = "./data";
public long SegMaxBytes { get; set; } = 256 * 1024 * 1024;
public int WriteQueueCapacity { get; set; } = 65536;
public string[] TagIndexKeys { get; set; } = Array.Empty<string>();
public uint NodeId { get; set; } = 0;
public string? LeaderAddress { get; set; } // Follower 模式必填
public int GrpcPort { get; set; } = 5100; // Leader 模式必填
}
依赖
<ProjectReference Include="..\WormDb.Core\WormDb.Core.csproj" />
<ProjectReference Include="..\WormDb.Cluster\WormDb.Cluster.csproj" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="10.0.8" />
使用
using WormDb.Extensions;
var builder = WebApplication.CreateBuilder(args);
// 1. 注册 WormDb 服务
builder.Services.AddWormDb(builder.Configuration.GetSection("WormDb"));
var app = builder.Build();
// 2. 映射 HTTP API 端点
app.MapWormDbHttpApi();
// 3. 启动
app.Run();
| 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 is compatible. 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
- WormDb.Cluster (>= 1.0.3)
- WormDb.Core (>= 1.0.9)
-
net8.0
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.8)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.8)
- WormDb.Cluster (>= 1.0.3)
- WormDb.Core (>= 1.0.9)
-
net9.0
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.8)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.8)
- WormDb.Cluster (>= 1.0.3)
- WormDb.Core (>= 1.0.9)
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 | 0 | 6/4/2026 |