using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.DependencyInjection; namespace Fengling.Member.Infrastructure; public class DesignTimeApplicationDbContextFactory: IDesignTimeDbContextFactory { public ApplicationDbContext CreateDbContext(string[] args) { IServiceCollection services = new ServiceCollection(); services.AddMediatR(c => c.RegisterServicesFromAssemblies(typeof(DesignTimeApplicationDbContextFactory).Assembly)); services.AddDbContext(options => { // change connectionstring if you want to run command “dotnet ef database update” options.UseNpgsql("Host=192.168.100.10;Database=fengling_member;Username=movingsam;Password=sl52788542", b => { b.MigrationsAssembly(typeof(DesignTimeApplicationDbContextFactory).Assembly.FullName); }); }); var provider = services.BuildServiceProvider(); var dbContext = provider.CreateScope().ServiceProvider.GetRequiredService(); return dbContext; } }