跳到主要内容

FreeKit 包能力矩阵

这页用于快速选包。先确定你要解决的问题,再进入对应包文档。

包清单

包名主要职责关键依赖文档
IGeekFan.FreeKit审计实体、依赖注入标记、领域事件MediatRCore
IGeekFan.FreeKit.ExtrasFreeSql 扩展、仓储、事务、当前用户、Autofac 注册FreeSql、AutofacExtras
IGeekFan.FreeKit.ModularityASP.NET Core 模块启动协议与 [module] 路由ASP.NET CoreModularity
IGeekFan.AspNetCore.Identity.FreeSqlASP.NET Core Identity 的 FreeSql StoreFreeSql、Identity.StoresIdentity.FreeSql
IGeekFan.Localization.FreeSql数据库本地化资源FreeSqlLocalization.FreeSql
IGeekFan.FreeKit.EmailMailKit 邮件发送MailKitEmail
IGeekFan.AspNetCore.DataProtection.FreeRedisDataProtection Key 存 RedisFreeRedisDataProtection.FreeRedis
IGeekFan.AspNetCore.DataProtection.FreeSqlDataProtection Key 存 FreeSqlFreeSqlDataProtection.FreeSql
IGeekFan.AspNetCore.SignalR.FreeRedisSignalR Redis backplaneFreeRedisSignalR.FreeRedis
IGeekFan.Extensions.Diagnostics.HealthChecks.FreeSqlFreeSql 健康检查FreeSql、HealthChecksHealthChecks.FreeSql
IGeekFan.OpenIddict.FreeSqlOpenIddict Store 的 FreeSql 实现OpenIddict.Core、FreeSqlOpenIddict.FreeSql
IGeekFan.R2.NETCloudflare R2 客户端AWSSDK.S3R2.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.FreeRedisSignalR.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");

包依赖关系

相关文档