From f33acacbbc3de5e97b4671392d76dbb29e50c061 Mon Sep 17 00:00:00 2001 From: movingsam Date: Sat, 21 Feb 2026 13:22:08 +0800 Subject: [PATCH] refactor(platform): migrate Tenant to anemia model, use Manager pattern - Convert Tenant to anemia model with long Id (no strong-typed ID) - Add ApplicationUser, ApplicationRole to Platform.Domain (inherit Identity) - Add TenantInfo value object for user-tenant redundancy - Implement TenantManager/TenantStore in Platform.Infrastructure - Update PlatformDbContext to inherit IdentityDbContext - Migrate AuthService and Console to use Platform entities - Remove old TenantRepository (replaced by TenantManager) - Update AGENTS.md documentation --- Program.cs | 57 ++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/Program.cs b/Program.cs index 7fd8278..50be5c6 100644 --- a/Program.cs +++ b/Program.cs @@ -1,18 +1,14 @@ using System.Reflection; -using Fengling.Console.Repositories; using Fengling.Console.Services; -using Fengling.Console.Stores; -using Fengling.Console.Managers; -using Fengling.Platform.Infrastructure.Repositories; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using OpenIddict.Abstractions; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Identity; using Microsoft.IdentityModel.Tokens; using System.Text; -using Fengling.Console.Datas; -using Fengling.Console.Models.Entities; -using Fengling.Platform.Infrastructure; using NetCorePal.Extensions.DependencyInjection; using OpenIddict.Validation.AspNetCore; using YarpGateway.Data; @@ -21,29 +17,32 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); -builder.Services.AddDbContext(options => +// Use PlatformDbContext for all identity +builder.Services.AddDbContext(options => { options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")); + if (builder.Environment.IsDevelopment()) + { + options.EnableSensitiveDataLogging(); + } + options.EnableDetailedErrors(); }); builder.Services.AddDbContext(options => options.UseNpgsql(builder.Configuration.GetConnectionString("GatewayConnection"))); -builder.Services.AddDbContext(options => - options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))); - +// Use Platform's identity builder.Services.AddIdentity() - .AddEntityFrameworkStores() + .AddEntityFrameworkStores() .AddDefaultTokenProviders(); builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpClient(); builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped, TenantStore>(); +// Register Platform managers +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -53,7 +52,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddOpenIddict() - .AddCore(options => { options.UseEntityFrameworkCore().UseDbContext(); }) + .AddCore(options => { options.UseEntityFrameworkCore().UseDbContext(); }) .AddValidation(options => { options.SetIssuer("http://localhost:5132/"); @@ -88,7 +87,7 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new() { Title = "Fengling.Console API", Version = "v1" }); - c.CustomSchemaIds(type => type.FullName); // Use full name to avoid conflicts with YarpGateway DTOs + c.CustomSchemaIds(type => type.FullName); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) @@ -97,31 +96,13 @@ builder.Services.AddSwaggerGen(c => } }); - -builder.Services.AddRepositories(typeof(ApplicationDbContext).Assembly,typeof(PlatformDbContext).Assembly); - -builder.Services.AddDbContext(options => -{ - options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL")); - // 仅在开发环境启用敏感数据日志,防止生产环境泄露敏感信息 - if (builder.Environment.IsDevelopment()) - { - options.EnableSensitiveDataLogging(); - } - - options.EnableDetailedErrors(); -}); -builder.Services.AddUnitOfWork(); -builder.Services.AddRedisLocks(); +builder.Services.AddRepositories(typeof(PlatformDbContext).Assembly); builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies( Assembly.GetExecutingAssembly(), typeof(PlatformDbContext).Assembly - ) - .AddCommandLockBehavior() - .AddKnownExceptionValidationBehavior() - .AddUnitOfWorkBehaviors()); + )); var app = builder.Build(); @@ -136,4 +117,4 @@ app.UseAuthorization(); app.MapControllers(); -app.Run(); \ No newline at end of file +app.Run();