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

            using (var scope = host.Services.CreateScope())
            {
                var services           = scope.ServiceProvider;
                var applicationContext = services.GetRequiredService <ApplicationContext>();
                var dbCreated          = applicationContext.Database.EnsureCreated();

                if (!dbCreated)
                {
                    try
                    {
                        InitializeDatabase.InitializeApplication(services).Wait();
                    }
                    catch (Exception ex)
                    {
                        var logger = services.GetRequiredService <ILogger <Program> >();
                        logger.LogError(ex, "An error occurred while initializing the Database");
                        throw;
                    }
                }
            }

            host.Run();
        }