fengling-platform/.planning/phases/01-gateway-routing/01-gateway-routing-CONTEXT.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

2.2 KiB

Phase 1: Gateway Routing Migration - Context

Gathered: 2026-02-28 Status: Ready for planning Source: User request (YARP gateway migration)

Phase Boundary

Migrate YARP gateway routing entities from fengling-gateway to Platform project:

  • GwTenant - 租户在网关中的配置
  • GwTenantRoute - 路由规则配置
  • GwServiceInstance - 服务实例管理

Output: Domain entities, Infrastructure (Store/Manager), Extensions for IoC

Implementation Decisions

Architecture Pattern

  • Manager + Store 模式: 与现有 Tenant 管理一致
    • ITenantStore → ITenantRouteStore
    • ITenantManager → ITenantRouteManager
    • 参考: Fengling.Platform.Infrastructure/TenantStore.cs, TenantManager.cs

Entity Design

  • GwTenant: 租户网关配置 (继承现有 Tenant 概念)
  • GwTenantRoute: 路由规则 (ClusterId, PathPattern, Priority)
  • GwServiceInstance: 服务实例 (Address, Health, Weight)

Extensions Pattern

  • 参考现有: Fengling.Platform.Infrastructure/Extensions.cs
  • 新增: AddGatewayCore<TContext>() 扩展方法
  • 注册: DbContext, IRouteStore, IRouteManager, IServiceInstanceStore

Database

  • PostgreSQL (已有)
  • 新迁移: Gateway 实体相关表

Specific Ideas

从 fengling-gateway 迁移的实体

../fengling-gateway/src/Models/GwTenant.cs
../fengling-gateway/src/Models/GwTenantRoute.cs  
../fengling-gateway/src/Models/GwServiceInstance.cs
../fengling-gateway/src/Data/GatewayDbContext.cs

Manager/Store 接口命名建议

ITenantRouteStore / TenantRouteStore
ITenantRouteManager / TenantRouteManager
IServiceInstanceStore / ServiceInstanceStore  
IServiceInstanceManager / ServiceInstanceManager

扩展方法签名

public static IServiceCollection AddGatewayCore<TContext>(this IServiceCollection services) 
    where TContext : GatewayDbContext;

Deferred Ideas

  • 服务发现集成 (后续阶段)
  • 动态配置热加载 (后续阶段)
  • 复杂的负载均衡策略 (后续阶段)

Claude's Discretion

  • 实体命名: 保持 Gw 前缀还是简化? (建议保留以避免冲突)
  • 是否复用现有 TenantStore? (建议新建独立 Store)
  • 是否需要 YARP 集成? (仅实体层,先不包含 YARP 特定配置)