fengling-platform/Fengling.Platform.Infrastructure/TenantManager.cs
movingsam 7877f89d35
Some checks failed
Build and Push Docker / build (push) Failing after 16s
Publish NuGet Packages / build (push) Failing after 1h7m51s
feat(platform): 增强 Infrastructure 层可扩展性,添加 NuGet 发布脚本与 CI/CD
## 主要变更

### Infrastructure 层重构
- `PlatformDbContext`: 构造函数改为接受泛型 `DbContextOptions`,支持派生上下文
- `TenantStore<TContext>`: 泛型化实现,支持不同的数据库上下文
- `Extensions`: 新增 `AddPlatformCore<TContext>` 扩展方法,简化服务注册

### 依赖调整
- 移除 Npgsql.EntityFrameworkCore.PostgreSQL 直接依赖,由使用方自行决定数据库提供程序

### CI/CD 集成
- 新增 `.gitea/workflows/publish-nuget.yml` Gitea Actions 工作流
- 新增 `push-platform-nuget.sh` 脚本,支持:
  - 从 git tag 自动获取版本号
  - HTTP/HTTPS 双模式支持
  - 独立 NuGet 配置文件
  - CI/CD 友好的环境变量配置

### 其他
- `NuGet.Config`: 新增 NuGet 配置文件
- `Fengling.Platform.Domain`: 添加 Items 文件夹占位
2026-02-27 13:58:09 +08:00

76 lines
3.5 KiB
C#

using Fengling.Platform.Domain.AggregatesModel.TenantAggregate;
using Microsoft.AspNetCore.Identity;
namespace Fengling.Platform.Infrastructure;
public interface ITenantManager
{
Task<Tenant?> FindByIdAsync(long? tenantId, CancellationToken cancellationToken = default);
Task<Tenant?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default);
Task<IList<Tenant>> GetAllAsync(CancellationToken cancellationToken = default);
Task<IList<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default);
Task<int> GetCountAsync(string? name = null, string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default);
Task<IdentityResult> CreateAsync(Tenant tenant, CancellationToken cancellationToken = default);
Task<IdentityResult> UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default);
Task<IdentityResult> DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default);
Task<int> GetUserCountAsync(long tenantId, CancellationToken cancellationToken = default);
Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default);
}
public sealed class TenantManager(ITenantStore store) : ITenantManager
{
public async Task<Tenant?> FindByIdAsync(long? tenantId, CancellationToken cancellationToken = default)
{
return await store.FindByIdAsync(tenantId, cancellationToken);
}
public async Task<Tenant?> FindByTenantCodeAsync(string tenantCode, CancellationToken cancellationToken = default)
{
return await store.FindByTenantCodeAsync(tenantCode, cancellationToken);
}
public async Task<IList<Tenant>> GetAllAsync(CancellationToken cancellationToken = default)
{
return await store.GetAllAsync(cancellationToken);
}
public async Task<IList<Tenant>> GetPagedAsync(int page, int pageSize, string? name = null,
string? tenantCode = null, TenantStatus? status = null, CancellationToken cancellationToken = default)
{
return await store.GetPagedAsync(page, pageSize, name, tenantCode, status, cancellationToken);
}
public async Task<int> GetCountAsync(string? name = null, string? tenantCode = null,
TenantStatus? status = null, CancellationToken cancellationToken = default)
{
return await store.GetCountAsync(name, tenantCode, status, cancellationToken);
}
public async Task<IdentityResult> CreateAsync(Tenant tenant, CancellationToken cancellationToken = default)
{
return await store.CreateAsync(tenant, cancellationToken);
}
public async Task<IdentityResult> UpdateAsync(Tenant tenant, CancellationToken cancellationToken = default)
{
return await store.UpdateAsync(tenant, cancellationToken);
}
public async Task<IdentityResult> DeleteAsync(Tenant tenant, CancellationToken cancellationToken = default)
{
return await store.DeleteAsync(tenant, cancellationToken);
}
public async Task<int> GetUserCountAsync(long tenantId, CancellationToken cancellationToken = default)
{
return await store.GetUserCountAsync(tenantId, cancellationToken);
}
public async Task<IdentityResult> SetTenantCodeAsync(Tenant tenant, string code, CancellationToken cancellationToken = default)
{
await store.SetTenantCodeAsync(tenant, code, cancellationToken);
return IdentityResult.Success;
}
}