FreeKit 包能力矩阵
这页用于快速选包。先确定你要解决的问题,再进入对应包文档。
包清单
| 包名 | 主要职责 | 关键依赖 | 文档 |
|---|---|---|---|
IGeekFan.FreeKit | 审计实体、依赖注入标记、领域事件 | MediatR | Core |
IGeekFan.FreeKit.Extras | FreeSql 扩展、仓储、事务、当前用户、Autofac 注册 | FreeSql、Autofac | Extras |
IGeekFan.FreeKit.Modularity | ASP.NET Core 模块启动协议与 [module] 路由 | ASP.NET Core | Modularity |
IGeekFan.AspNetCore.Identity.FreeSql | ASP.NET Core Identity 的 FreeSql Store | FreeSql、Identity.Stores | Identity.FreeSql |
IGeekFan.Localization.FreeSql | 数据库本地化资源 | FreeSql | Localization.FreeSql |
IGeekFan.FreeKit.Email | MailKit 邮件发送 | MailKit | |
IGeekFan.AspNetCore.DataProtection.FreeRedis | DataProtection Key 存 Redis | FreeRedis | DataProtection.FreeRedis |
IGeekFan.AspNetCore.DataProtection.FreeSql | DataProtection Key 存 FreeSql | FreeSql | DataProtection.FreeSql |
IGeekFan.AspNetCore.SignalR.FreeRedis | SignalR Redis backplane | FreeRedis | SignalR.FreeRedis |
IGeekFan.Extensions.Diagnostics.HealthChecks.FreeSql | FreeSql 健康检查 | FreeSql、HealthChecks | HealthChecks.FreeSql |
IGeekFan.OpenIddict.FreeSql | OpenIddict Store 的 FreeSql 实现 | OpenIddict.Core、FreeSql | OpenIddict.FreeSql |
IGeekFan.R2.NET | Cloudflare R2 客户端 | AWSSDK.S3 | R2.NET |
按场景选包
需要审计实体和领域事件
选择:Core
// 审计实体
public class Article : FullAuditEntity<Guid, Guid>, ITenant
{
public Guid? TenantId { get; set; }
public string Title { get; set; } = default!;
}
// 领域事件
public sealed record ArticlePublishedEvent(Guid ArticleId) : IDomainEvent;
需要 FreeSql 仓储和事务
选择:Extras
// 事务
[Transactional]
public async Task TransferAsync(Guid fromId, Guid toId, decimal amount)
{
// 原子操作
}
// 当前用户
var userId = CurrentUser.FindUserId();
需要模块化单体
选择:Modularity
// 模块启动
public class OrderStartup : IModuleStartup
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IOrderService, OrderService>();
}
}
// 路由: /api/order/order/{id}
[ApiController]
[Route("api/[module]/[controller]")]
public class OrderController : ControllerBase { }
需要用户认证
选择:Identity.FreeSql
// 用户注册
var user = new AppUser { Email = "test@example.com" };
await _userManager.CreateAsync(user, "password");
// 用户登录
var result = await _signInManager.PasswordSignInAsync(user, "password");
需要多语言
选择:Localization.FreeSql
// 使用本地化
return _localizer["Hello"]; // 根据语言返回 "Hello" 或 "你好"
需要邮件发送
选择:Email
// 发送验证码
var message = new MimeMessage();
message.To.Add(new MailboxAddress("User", "user@example.com"));
message.Subject = "验证码";
message.Body = new TextPart("html") { Text = "验证码:123456" };
await _emailSender.SendAsync(message);
需要分布式缓存
选择:DataProtection.FreeRedis 或 SignalR.FreeRedis
// DataProtection
builder.Services.AddDataProtection()
.PersistKeysToFreeRedis(redis, "DataProtection-Keys");
// SignalR
builder.Services.AddSignalR()
.AddFreeRedis(connectionString);
需要数据库健康检查
选择:HealthChecks.FreeSql
builder.Services.AddHealthChecks()
.AddFreeSql(fsql, name: "freesql");
app.MapHealthChecks("/health");
需要 OAuth2 授权服务
选择:OpenIddict.FreeSql
builder.Services.AddOpenIddict()
.AddCore(options => options.AddFreeSqlStores())
.AddServer(options =>
{
options.AllowAuthorizationCodeFlow();
});
需要对象存储
选择:R2.NET
// 上传文件
var url = await client.UploadBlobAsync(stream, "file.pdf");
// 下载文件
var stream = await client.GetBlobAsync("file.pdf");