34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace BlazingPizza.Server
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var host = CreateHostBuilder(args).Build();
|
|
|
|
// Initialize the database
|
|
var scopeFactory = host.Services.GetRequiredService<IServiceScopeFactory>();
|
|
using (var scope = scopeFactory.CreateScope())
|
|
{
|
|
var db = scope.ServiceProvider.GetRequiredService<PizzaStoreContext>();
|
|
if (db.Database.EnsureCreated())
|
|
{
|
|
SeedData.Initialize(db);
|
|
}
|
|
}
|
|
|
|
host.Run();
|
|
}
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
}
|
|
}
|