Cleaning up EF 2.0 Migrations (#57)

Moving Seed logic to Program.cs
This commit is contained in:
Steve Smith
2017-10-18 14:25:10 -04:00
committed by GitHub
parent 8de663eab6
commit 32950aa175
9 changed files with 456 additions and 221 deletions

View File

@@ -1,14 +1,46 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
using Infrastructure.Data;
using System;
using Microsoft.Extensions.Logging;
using Infrastructure.Identity;
using Microsoft.AspNetCore.Identity;
namespace Microsoft.eShopWeb
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
var host = BuildWebHost(args);
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var catalogContext = services.GetRequiredService<CatalogContext>();
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
CatalogContextSeed.SeedAsync(catalogContext, loggerFactory)
.Wait();
// move to IdentitySeed method
var userManager = services.GetRequiredService<UserManager<ApplicationUser>>();
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
//var logger = services.GetRequiredService<ILogger<Program>>();
//logger.LogError(ex, "An error occurred seeding the DB.");
}
}
host.Run();
}
public static IWebHost BuildWebHost(string[] args) =>