public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; using (var context = services.GetService <AppDbContext>()) { context.Database.Migrate(); AppDbContextSeed.Seed(context); } using (var context = services.GetService <AppIdentityDbContext>()) { context.Database.Migrate(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await AppIdentityDbContextSeed.SeedAsync(userManager, roleManager); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var ctx = scope.ServiceProvider.GetService <AppDbContext>(); AppDbContextSeed.Seed(ctx); } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var ctx = scope.ServiceProvider.GetService <AppDbContext>(); AppDbContextSeed.Seed(ctx); var cronManager = scope.ServiceProvider.GetService <ICronJobsManager>(); cronManager.RegisterAllCronJobs(); } host.Run(); }
private static async Task InitDatabase(IHost host) { using IServiceScope scope = host.Services.CreateScope(); var context = scope.ServiceProvider.GetRequiredService <AppDbContext>(); //await context.Database.EnsureDeletedAsync(); if ((await context.Database.GetPendingMigrationsAsync()).Any()) { await context.Database.MigrateAsync(); } var hasher = scope.ServiceProvider.GetService <IPasswordHasher>(); await AppDbContextSeed.Seed(context, hasher); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var catalogContext = scope.ServiceProvider.GetRequiredService <AppDbContext>(); var userManager = scope.ServiceProvider.GetRequiredService <UserManager <IdentityUser> >(); var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); AppIdentityContextSeed.SeedASync(userManager, roleManager).Wait(); AppDbContextSeed.Seed(catalogContext); } host.Run(); }