Example #1
0
        public static void Main(string[] args)
        {
//            var host = new WebHostBuilder()
//             .UseContentRoot(Directory.GetCurrentDirectory())
//             .UseKestrel()
////             .UseKestrel(options =>
////             {
//// //                options.Listen(IPAddress.Loopback, 5001, listenOptions =>
///////                 {
//////                     listenOptions.UseHttps("testCert.pfx", "testPassword");
//////                     listenOptions.UseConnectionLogging();
//////                 });
////             })
//////             .UseIISIntegration()
//             .UseStartup<Startup>()
//             .Build();

//            host.Run();
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var ctx = services.GetRequiredService <ApplicationDbContext>();
                    ctx.Database.Migrate();

                    AppSeed.SeedAsync(services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while attempting to seed data.");
                }
            }
            host.Run();
        }