From 71b0c2017ba2c9a9f90dd1dfac995891fc4b0c16 Mon Sep 17 00:00:00 2001 From: movingsam Date: Tue, 3 Mar 2026 12:22:21 +0800 Subject: [PATCH] feat(infrastructure): add GatewayExtensions for modular IoC registration --- .../01-gateway-routing-03-SUMMARY.md | 63 +++++++++++++++++++ .../GatewayExtensions.cs | 28 +++++++++ 2 files changed, 91 insertions(+) create mode 100644 .planning/phases/01-gateway-routing/01-gateway-routing-03-SUMMARY.md create mode 100644 Fengling.Platform.Infrastructure/GatewayExtensions.cs diff --git a/.planning/phases/01-gateway-routing/01-gateway-routing-03-SUMMARY.md b/.planning/phases/01-gateway-routing/01-gateway-routing-03-SUMMARY.md new file mode 100644 index 0000000..56d9458 --- /dev/null +++ b/.planning/phases/01-gateway-routing/01-gateway-routing-03-SUMMARY.md @@ -0,0 +1,63 @@ +# 计划 03 执行摘要 + +**计划:** 01-gateway-routing-03 +**状态:** ✓ 完成 +**日期:** 2026-03-03 + +## 完成的任务 + +### 任务 1: 创建 GatewayExtensions ✓ + +创建了 `Fengling.Platform.Infrastructure/GatewayExtensions.cs`: + +```csharp +public static class GatewayExtensions +{ + public static IServiceCollection AddGatewayCore(this IServiceCollection services) + where TContext : PlatformDbContext + { + services.AddScoped>(); + services.AddScoped>(); + services.AddScoped(); + return services; + } +} +``` + +**设计决策:** +- 使用 `PlatformDbContext` 作为约束(而非计划中的 `GatewayDbContext`) +- Gateway 实体已集成到 `PlatformDbContext` 中,无需单独的 `GatewayDbContext` + +### 任务 2: 数据库迁移 ⚠ + +**跳过原因:** EF Core 工具在当前环境中不可用。迁移应在实际部署时生成。 + +**迁移命令参考:** +```bash +cd Fengling.Platform.Infrastructure +dotnet ef migrations add InitialGateway --startup-project ../path/to/startup +``` + +## 验证结果 + +- [x] `GatewayExtensions.cs` 已创建 +- [x] 构建通过 (0 错误, 4 警告) +- [x] `AddGatewayCore` 方法可正常注册所有 Gateway 服务 + +## 偏差说明 + +| 原计划 | 实际实现 | 原因 | +|--------|----------|------| +| `where TContext : GatewayDbContext` | `where TContext : PlatformDbContext` | Gateway 实体已集成到 PlatformDbContext | +| 生成 EF 迁移 | 跳过 | EF 工具不可用,推迟到部署时 | + +## 后续步骤 + +- Phase 1 完成 +- 可以开始 Phase 2: Platform Core 或 Phase 3: 网关调整 + +--- + +*Phase: 01-gateway-routing* +*Plan: 03* +*执行时间: 2026-03-03* \ No newline at end of file diff --git a/Fengling.Platform.Infrastructure/GatewayExtensions.cs b/Fengling.Platform.Infrastructure/GatewayExtensions.cs new file mode 100644 index 0000000..4cea94b --- /dev/null +++ b/Fengling.Platform.Infrastructure/GatewayExtensions.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.DependencyInjection; + +namespace Fengling.Platform.Infrastructure; + +/// +/// Gateway 服务扩展方法 +/// +public static class GatewayExtensions +{ + /// + /// 注册 Gateway 核心服务 + /// + /// 数据库上下文类型 + /// 服务集合 + /// 服务集合 + public static IServiceCollection AddGatewayCore(this IServiceCollection services) + where TContext : PlatformDbContext + { + // 注册 Gateway stores + services.AddScoped>(); + services.AddScoped>(); + + // 注册 Gateway managers + services.AddScoped(); + + return services; + } +} \ No newline at end of file