public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); try { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); RolesInitializer.Initialize(userManager, roleManager); } catch (Exception e) { Log.Fatal(e, "Unable to create user roles."); } } Log.Information("Application is starting up."); host.Run(); Log.Information("Application is shutting down."); }
public Task Invoke(HttpContext context) { if (!(context.Session.Keys.Contains("starting"))) { RolesInitializer.Initialize(context).Wait(); context.Session.SetString("starting", "Yes"); } // Вызов следующего делегата / компонента middleware в конвейере return(_next.Invoke(context)); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); Task t = RolesInitializer.Initialize(rolesManager); t.Wait(); } host.Run(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; var context = serviceProvider.GetRequiredService <ApplicationContext>(); var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); await DataInitializer.Initialize(context); await RolesInitializer.Initialize(userManager, roleManager); } host.Run(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); try { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); RolesInitializer.Initialize(userManager, roleManager); Log.Information("Database initialization"); } catch (Exception ex) { Log.Fatal(ex, "Initialization of Database has failed"); } } try { Log.Information("Application starting up."); host.Run(); } catch (Exception ex) { Log.Fatal(ex, "Application has failed to start."); } finally { Log.CloseAndFlush(); } }