fengling-platform/.planning/phases/01-gateway-routing/01-gateway-routing-03-PLAN.md
movingsam 1b8c937aa4
Some checks failed
Build and Push Docker / build (push) Failing after 23s
Publish NuGet Packages / build (push) Failing after 8s
feat: 添加 Gateway 路由实体到 Platform
- 新增 GatewayAggregate 领域实体 (GwTenant, GwTenantRoute, GwServiceInstance)
- 新增 IRouteStore, RouteStore, IInstanceStore, InstanceStore
- 新增 IRouteManager, RouteManager
- 合并 GatewayDbContext 到 PlatformDbContext
- 统一 Extensions.AddPlatformCore 注册所有服务
2026-02-28 23:53:00 +08:00

3.2 KiB

phase plan type wave depends_on files_modified autonomous requirements must_haves
01-gateway-routing 03 execute 2
01-gateway-routing-01
01-gateway-routing-02
Fengling.Platform.Infrastructure/GatewayExtensions.cs
true
GATEWAY-04
GATEWAY-05
truths artifacts key_links
Extensions 方法注册所有 Gateway 服务
DI 中 AddGatewayCore 后服务可用
可以生成数据库迁移
path provides exports
Fengling.Platform.Infrastructure/GatewayExtensions.cs AddGatewayCore<TContext> 扩展方法
GatewayDbContext
IRouteStore
IRouteManager
IInstanceStore
from to via pattern
AddGatewayCore AddPlatformCore 可以一起调用 services.AddPlatformCore<T>().AddGatewayCore<T>()

计划 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 迁移:
  1. 创建初始迁移:

    • 从 Infrastructure 目录
    • 迁移名称: InitialGateway
  2. 验证迁移包含:

    • 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));