public static async Task Main(string[] args) { var hostBuilder = CreateHostBuilder(args).Build(); using (var scope = hostBuilder.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <User> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitializer.InitializeDBAsync(userManager, rolesManager); } catch { } } hostBuilder.Run(); }