public static async Task Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); await DataHelper.ManageData(host); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var imageService = services.GetRequiredService <IImageService>(); var context = services.GetRequiredService <ApplicationDbContext>(); var userManager = services.GetRequiredService <UserManager <BTUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await ContextSeed.RunSeedMethods(roleManager, userManager, context, imageService); } catch (Exception ex) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }