4.3 KiB
4.3 KiB
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | user_setup | must_haves | |||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 01-gateway-config-management | 01 | execute | 1 |
|
true |
|
-
修改构造函数:
- 注入 ConsoleDbContext(而非使用 IConfiguration)
- 使用 DbContext.Database.GetConnectionString() 获取连接字符串
-
移除:
- IConfiguration 依赖
- _configuration.GetConnectionString("DefaultConnection")
-
示例代码:
public PgSqlNotificationService( ConsoleDbContext dbContext, ILogger<PgSqlNotificationService> logger) { _connectionString = dbContext.Database.GetConnectionString() ?? throw new InvalidOperationException("DefaultConnection not configured"); _logger = logger; } -
在 Program.cs 中注册服务时传入 DbContext:
services.AddScoped<INotificationService>(sp => new PgSqlNotificationService( sp.GetRequiredService<ConsoleDbContext>(), sp.GetRequiredService<ILogger<PgSqlNotificationService>>()));
-
添加 INotificationService 依赖注入到 GatewayService 构造函数
-
修改 ReloadGatewayAsync() 实现:
- 调用 _notificationService.PublishAsync("gateway_config_changed", JsonSerialize(reloadEvent))
- 日志记录广播成功
-
在以下 CRUD 操作中添加自动广播(创建/更新/删除后):
- RegisterServiceAsync - 服务注册
- UnregisterServiceAsync - 服务注销
- CreateRouteAsync - 路由创建
- AddInstanceAsync - 实例添加
- RemoveInstanceAsync - 实例删除
- UpdateInstanceWeightAsync - 权重更新
-
事件 Payload 格式:
{ "eventType": "service|route|instance", "action": "create|update|delete|reload", "timestamp": "2026-03-02T12:00:00Z", "details": { ... } }
<success_criteria>
- ConfigNotificationService 改为使用 DbContext 获取连接字符串
- INotificationService 接口定义完成
- PgSqlNotificationService 实现完成
- GatewayService 集成通知服务
- ReloadGatewayAsync 触发广播
- CRUD 操作自动触发广播
- 编译通过 </success_criteria>