feat(infrastructure): add GatewayExtensions for modular IoC registration

This commit is contained in:
movingsam 2026-03-03 12:22:21 +08:00
parent 8e19a4c1bd
commit 71b0c2017b
2 changed files with 91 additions and 0 deletions

View File

@ -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<TContext>(this IServiceCollection services)
where TContext : PlatformDbContext
{
services.AddScoped<IRouteStore, RouteStore<TContext>>();
services.AddScoped<IInstanceStore, InstanceStore<TContext>>();
services.AddScoped<IRouteManager, RouteManager>();
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<TContext>` 方法可正常注册所有 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*

View File

@ -0,0 +1,28 @@
using Microsoft.Extensions.DependencyInjection;
namespace Fengling.Platform.Infrastructure;
/// <summary>
/// Gateway 服务扩展方法
/// </summary>
public static class GatewayExtensions
{
/// <summary>
/// 注册 Gateway 核心服务
/// </summary>
/// <typeparam name="TContext">数据库上下文类型</typeparam>
/// <param name="services">服务集合</param>
/// <returns>服务集合</returns>
public static IServiceCollection AddGatewayCore<TContext>(this IServiceCollection services)
where TContext : PlatformDbContext
{
// 注册 Gateway stores
services.AddScoped<IRouteStore, RouteStore<TContext>>();
services.AddScoped<IInstanceStore, InstanceStore<TContext>>();
// 注册 Gateway managers
services.AddScoped<IRouteManager, RouteManager>();
return services;
}
}