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

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                var logger        = loggerFactory.CreateLogger <Program>();
                try
                {
                    var environment = services.GetRequiredService <IWebHostEnvironment>();

                    if (environment.IsDevelopment())
                    {
                        var context = services.GetRequiredService <Infrastructure.AppDbContext>();
                        MigrateDatabaseToLatestVersion.ExecuteAsync(context).Wait();
                    }
                }
                catch (AppException ex)
                {
                    logger.LogError(ex, "An error occurred creating/updating the DB.");
                }
            }

            host.Run();
        }