feat: add DataSeeder for reference/test data and auto-migration on startup

This commit is contained in:
2026-06-09 01:31:37 +03:30
parent f101085b52
commit 8be6133661
2 changed files with 526 additions and 0 deletions

View File

@@ -19,6 +19,9 @@ using Swashbuckle.AspNetCore.SwaggerGen;
using System.Reflection;
using System.Text;
using WebApi.Bugeto.Models.Services.Validator;
using Complex.Application.Services.TransactionServices;
using Complex.Application.Services.Announcement;
using Complex.Application.Services.Dashboard;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
@@ -40,6 +43,9 @@ builder.Services.AddScoped<ISiteAccountlService, SiteAccountlService>();
builder.Services.AddScoped<IUserTokenService, UserTokenService>();
builder.Services.AddScoped<ISendUserMessage, SmsService>();
builder.Services.AddScoped<ITokenValidator, TokenValidate>();
builder.Services.AddScoped<ITransactionService, TransactionService>();
builder.Services.AddScoped<IAnnouncementService, AnnouncementService>();
builder.Services.AddScoped<IDashboardService, DashboardService>();
//eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIqQCFJVE15QXpNX19fSVRPeGtETSIsIk5hbWUiOiIqQCE4S18xXzFfRm1kcllYWV8xXzFfIiwiRmFtaWx5IjoiKkAhKkAhQWpiWFlfMV8xX011ZHJZSExfMV8xXyIsIm5iZiI6MTcwNjg4ODQyOCwiZXhwIjoxNzA5NDgwNDI4LCJpc3MiOiJuYWJha3NvZnQuaXIiLCJhdWQiOiJDb21wbGV4In0.Hz7fF-bRW3KouPOGgc0p5UVCMQmKkroKzGLdmZeXZeg
@@ -170,6 +176,16 @@ builder.Services.AddSwaggerGen(c =>
var app = builder.Build();
// Apply pending migrations automatically on startup
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ComplexDBContext>();
dbContext.Database.Migrate();
// Seed essential reference data and test data
await DataSeeder.SeedAsync(dbContext);
}
app.UseExceptionHandler(c => c.Run(async context =>
{
var exception = context.Features