public static async Task EnsureDataSeeded(IServiceProvider serviceProvider) { using (var scope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var seeder = new Seeder(context); await seeder.Seed(); } }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); if (args.Contains("--seed")) { Seeder.EnsureDataSeeded(host.Services).GetAwaiter().GetResult(); } host.Run(); }