public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { Task t; var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ArduinoContext>(); ArduinoInitializer.Initialize(context); var context2 = services.GetRequiredService <MeasurementContext>(); MeasurementInitializer.Initialize(context2); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); t = IdentityInitializer.InitializeAsync(userManager, rolesManager); t.Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var service = scope.ServiceProvider; var userService = service.GetRequiredService <IUserService>(); var roleService = service.GetRequiredService <IRoleService>(); await IdentityInitializer.InitializeAsync(userService, roleService); host.Run(); } }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <IdentityBuyer> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await IdentityInitializer.InitializeAsync(userManager, roleManager); } host.Run(); }
private async Task InitializeDB(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var context = serviceScope.ServiceProvider.GetRequiredService <EFDbContext>(); if (!(context.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists()) { context.Database.EnsureCreated(); } var service = serviceScope.ServiceProvider; var userService = service.GetRequiredService <IUserService>(); var roleService = service.GetRequiredService <IRoleService>(); await IdentityInitializer.InitializeAsync(userService, roleService); } }