fengling-platform/Fengling.Platform.Infrastructure/Extensions.cs
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

35 lines
1.1 KiB
C#

using Microsoft.Extensions.DependencyInjection;
namespace Fengling.Platform.Infrastructure;
public static class Extensions
{
public static IServiceCollection AddPlatformCore<TContext>(this IServiceCollection services,
Action<DbContextOptionsBuilder>? optionsAction = null,
Action<IServiceCollection>? serviceAction = null
)
where TContext : PlatformDbContext
{
if (optionsAction != null)
{
var isRegistry = services.Any(x => x.ImplementationType == typeof(TContext));
if (!isRegistry)
{
services.AddDbContext<TContext>(optionsAction);
}
}
// Platform 服务
services.AddScoped<ITenantStore, TenantStore<TContext>>();
services.AddScoped<ITenantManager, TenantManager>();
// Gateway 服务
services.AddScoped<IRouteStore, RouteStore<TContext>>();
services.AddScoped<IInstanceStore, InstanceStore<TContext>>();
services.AddScoped<IRouteManager, RouteManager>();
serviceAction?.Invoke(services);
return services;
}
}