Y3S1-Cloud_Systems_DevOps/ThAmCo-Products/ThAmCo.Products/Program.cs
2020-06-09 21:21:37 +01:00

35 lines
1.0 KiB
C#

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using ThAmCo.Products.Data;
namespace ThAmCo.Products
{
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>();
if (env.IsDevelopment())
{
var context = services.GetRequiredService<ProductsDbContext>();
context.Database.EnsureDeleted();
context.Database.Migrate();
}
}
host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}