- 新增 GatewayAggregate 领域实体 (GwTenant, GwTenantRoute, GwServiceInstance) - 新增 IRouteStore, RouteStore, IInstanceStore, InstanceStore - 新增 IRouteManager, RouteManager - 合并 GatewayDbContext 到 PlatformDbContext - 统一 Extensions.AddPlatformCore 注册所有服务
3.2 KiB
3.2 KiB
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | must_haves | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 01-gateway-routing | 03 | execute | 2 |
|
|
true |
|
|
计划 03: 网关扩展方法
目标
创建 Extensions 类用于快速 IoC 注册 Gateway 服务。
目的: 支持单行注册所有 Gateway 服务,类似于 AddPlatformCore。
输出: 包含 AddGatewayCore 方法的 GatewayExtensions.cs。
上下文
@Fengling.Platform.Infrastructure/Extensions.cs (模式参考) @Fengling.Platform.Infrastructure/GatewayDbContext.cs (来自计划 02)
任务
任务 1: 创建 GatewayExtensions Fengling.Platform.Infrastructure/GatewayExtensions.cs 创建 GatewayExtensions 静态类:public static class GatewayExtensions
{
public static IServiceCollection AddGatewayCore<TContext>(this IServiceCollection services)
where TContext : GatewayDbContext
{
// 注册 Gateway stores
services.AddScoped<IRouteStore, RouteStore<TContext>>();
services.AddScoped<IInstanceStore, InstanceStore<TContext>>();
// 注册 Gateway managers
services.AddScoped<IRouteManager, RouteManager>();
return services;
}
}
参考: Fengling.Platform.Infrastructure/Extensions.cs 模式 dotnet build Fengling.Platform.Infrastructure AddGatewayCore 扩展方法注册所有 Gateway 服务
任务 2: 生成数据库迁移 Fengling.Platform.Infrastructure/Migrations/ 为 Gateway 实体生成 EF Core 迁移:-
创建初始迁移:
- 从 Infrastructure 目录
- 迁移名称: InitialGateway
-
验证迁移包含:
- GwTenants 表
- GwTenantRoutes 表
- GwServiceInstances 表
- GatewayDbContext 中定义的所有索引 dotnet ef migrations list --project Fengling.Platform.Infrastructure 迁移已生成并列出
验证
- GatewayExtensions.cs 可编译
- AddGatewayCore 方法注册所有服务
- 迁移成功生成
- Build 通过
成功标准
Gateway 路由功能完全集成并可使用。
使用示例
// 在 Program.cs 或 startup 中
services.AddPlatformCore<PlatformDbContext>(options =>
options.UseNpgsql(connectionString));
services.AddGatewayCore<GatewayDbContext>(options =>
options.UseNpgsql(gatewayConnectionString));