namespace Fengling.Platform.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.DependencyInjection; public class DesignTimeApplicationDbContextFactory : IDesignTimeDbContextFactory { public PlatformDbContext CreateDbContext(string[] args) { IServiceCollection services = new ServiceCollection(); services.AddMediatR(c => c.RegisterServicesFromAssemblies(typeof(DesignTimeApplicationDbContextFactory).Assembly)); services.AddDbContext(options => { options.UseNpgsql("Host=localhost;Database=fengling_platform;Username=postgres;Password=postgres", b => { b.MigrationsAssembly(typeof(DesignTimeApplicationDbContextFactory).Assembly.FullName); }); }); var provider = services.BuildServiceProvider(); var dbContext = provider.CreateScope().ServiceProvider.GetRequiredService(); return dbContext; } }