public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var dataBase = services.GetRequiredService <DataContext>(); var userManager = services.GetRequiredService <UserManager <AppUser> >(); var roleManager = services.GetRequiredService <RoleManager <Role> >(); dataBase.Database.Migrate(); Seed.AddData(dataBase, userManager, roleManager).Wait(); } catch (System.Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration"); } } host.Run(); }