Esempio n. 1
0
        public static async Task Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json", true, true)
                         .Build();

            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(config)
                         .CreateLogger();

            Log.Information("AtmosAQ starting up...");

            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    Log.Information("Database migration...");

                    var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();
                    await dbContext.Database.MigrateAsync();

                    Log.Information("Seeding default user...");

                    var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                    await DatabaseSeed.SeedDefaultUSerAsync(userManager);
                }
                catch (Exception ex)
                {
                    Log.Fatal(ex, "Error during migration or seeding the database.");
                    throw;
                }
            }

            await host.RunAsync();
        }