public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeAsync(rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } try { var context = services.GetRequiredService <DataContext>(); DbData.Initialize(context); /*var cart_context = services.GetRequiredService<CartContext>(); * var user_context = services.GetRequiredService<UserDataContext>(); * DbData.InitCart(cart_context, user_context);*/ } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }