Y2S1-Web_Apps_and_Services/ThAmCo.Catering/Program.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2020-06-07 21:36:12 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using ThAmCo.Venues.Data;
namespace ThAmCo.Catering
{
public class Program
{
public static void Main(string[] args)
{
var host = CreateWebHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
var env = services.GetRequiredService<IHostingEnvironment>();
var context = services.GetRequiredService<CateringDbContext>();
if (env.IsDevelopment())
{
context.Database.EnsureDeleted();
}
context.Database.Migrate();
}
host.Run();
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}