Пример #1
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                System.Threading.Tasks.Task t;
                var services = scope.ServiceProvider;
                try
                {
                    var userManager  = services.GetRequiredService <UserManager <User> >();
                    var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >();

                    t = RoleInitializer.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();
        }
Пример #2
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var userManager  = services.GetRequiredService <UserManager <User> >();
                    var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await RoleInitializer.InitializeAsync(userManager, rolesManager);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }