예제 #1
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var serviceProvider = services.GetRequiredService <IServiceProvider>();
                    var configuration   = services.GetRequiredService <IConfiguration>();

                    RolesManager.CreateRoles(serviceProvider).Wait();
                    UsersManager.CreateSuperUser(serviceProvider, configuration).Wait();

                    var context = services.GetRequiredService <ApplicationDbContext>();
                    DbInitializer.Initialize(context);
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(exception, "An error occurred while creating roles");
                }
            }

            host.Run();
        }