Last active
April 19, 2018 04:09
-
-
Save gmartinezsan/5ace678988c7290adb69ea9ed7b107e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using BooksWebApi.Data; | |
using BooksWebApi.Entities; | |
using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Identity; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
namespace BooksWebApi | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var host = BuildWebHost(args); | |
using (var scope = host.Services.CreateScope()) | |
{ | |
var services = scope.ServiceProvider; | |
try | |
{ | |
var context = services.GetRequiredService<BooksCatalogDbContext>(); | |
var userManager = services.GetRequiredService<UserManager<User>>(); | |
var roleManager = services.GetRequiredService<RoleManager<IdentityRole>>(); | |
DataInitializer.Seed(userManager, roleManager, context); | |
} | |
catch (Exception ex) | |
{ | |
var logger = services.GetRequiredService<ILogger<Program>>(); | |
logger.LogError(ex, "An error occurred while seeding the database."); | |
} | |
} | |
host.Run(); | |
} | |
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) | |
.UseStartup<Startup>() | |
.Build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment