- 新增 GatewayAggregate 领域实体 (GwTenant, GwTenantRoute, GwServiceInstance) - 新增 IRouteStore, RouteStore, IInstanceStore, InstanceStore - 新增 IRouteManager, RouteManager - 合并 GatewayDbContext 到 PlatformDbContext - 统一 Extensions.AddPlatformCore 注册所有服务
125 lines
3.2 KiB
Markdown
125 lines
3.2 KiB
Markdown
---
|
|
phase: 01-gateway-routing
|
|
plan: 03
|
|
type: execute
|
|
wave: 2
|
|
depends_on:
|
|
- 01-gateway-routing-01
|
|
- 01-gateway-routing-02
|
|
files_modified:
|
|
- Fengling.Platform.Infrastructure/GatewayExtensions.cs
|
|
autonomous: true
|
|
requirements:
|
|
- GATEWAY-04
|
|
- GATEWAY-05
|
|
must_haves:
|
|
truths:
|
|
- "Extensions 方法注册所有 Gateway 服务"
|
|
- "DI 中 AddGatewayCore 后服务可用"
|
|
- "可以生成数据库迁移"
|
|
artifacts:
|
|
- path: "Fengling.Platform.Infrastructure/GatewayExtensions.cs"
|
|
provides: "AddGatewayCore<TContext> 扩展方法"
|
|
exports: ["GatewayDbContext", "IRouteStore", "IRouteManager", "IInstanceStore"]
|
|
key_links:
|
|
- from: "AddGatewayCore"
|
|
to: "AddPlatformCore"
|
|
via: "可以一起调用"
|
|
pattern: "services.AddPlatformCore<T>().AddGatewayCore<T>()"
|
|
---
|
|
|
|
# 计划 03: 网关扩展方法
|
|
|
|
## 目标
|
|
|
|
创建 Extensions 类用于快速 IoC 注册 Gateway 服务。
|
|
|
|
**目的:** 支持单行注册所有 Gateway 服务,类似于 AddPlatformCore。
|
|
|
|
**输出:** 包含 AddGatewayCore<TContext> 方法的 GatewayExtensions.cs。
|
|
|
|
## 上下文
|
|
|
|
@Fengling.Platform.Infrastructure/Extensions.cs (模式参考)
|
|
@Fengling.Platform.Infrastructure/GatewayDbContext.cs (来自计划 02)
|
|
|
|
## 任务
|
|
|
|
<task type="auto">
|
|
<name>任务 1: 创建 GatewayExtensions</name>
|
|
<files>Fengling.Platform.Infrastructure/GatewayExtensions.cs</files>
|
|
<action>
|
|
创建 GatewayExtensions 静态类:
|
|
|
|
```csharp
|
|
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 模式
|
|
</action>
|
|
<verify>
|
|
<automated>dotnet build Fengling.Platform.Infrastructure</automated>
|
|
</verify>
|
|
<done>AddGatewayCore 扩展方法注册所有 Gateway 服务</done>
|
|
</task>
|
|
|
|
<task type="auto">
|
|
<name>任务 2: 生成数据库迁移</name>
|
|
<files>Fengling.Platform.Infrastructure/Migrations/</files>
|
|
<action>
|
|
为 Gateway 实体生成 EF Core 迁移:
|
|
|
|
1. 创建初始迁移:
|
|
- 从 Infrastructure 目录
|
|
- 迁移名称: InitialGateway
|
|
|
|
2. 验证迁移包含:
|
|
- GwTenants 表
|
|
- GwTenantRoutes 表
|
|
- GwServiceInstances 表
|
|
- GatewayDbContext 中定义的所有索引
|
|
</action>
|
|
<verify>
|
|
<automated>dotnet ef migrations list --project Fengling.Platform.Infrastructure</automated>
|
|
</verify>
|
|
<done>迁移已生成并列出</done>
|
|
</task>
|
|
|
|
</tasks>
|
|
|
|
## 验证
|
|
|
|
- [ ] GatewayExtensions.cs 可编译
|
|
- [ ] AddGatewayCore 方法注册所有服务
|
|
- [ ] 迁移成功生成
|
|
- [ ] Build 通过
|
|
|
|
## 成功标准
|
|
|
|
Gateway 路由功能完全集成并可使用。
|
|
|
|
## 使用示例
|
|
|
|
```csharp
|
|
// 在 Program.cs 或 startup 中
|
|
services.AddPlatformCore<PlatformDbContext>(options =>
|
|
options.UseNpgsql(connectionString));
|
|
|
|
services.AddGatewayCore<GatewayDbContext>(options =>
|
|
options.UseNpgsql(gatewayConnectionString));
|
|
```
|