Skip to content

Instantly share code, notes, and snippets.

@nshathish
Last active December 8, 2017 15:42
Show Gist options
  • Save nshathish/a008ca271753725555f78c6410cbb47a to your computer and use it in GitHub Desktop.
Save nshathish/a008ca271753725555f78c6410cbb47a to your computer and use it in GitHub Desktop.
asp.net core program.cs with seed data method
public class Program
{
public static void Main(string[] args)
{
var host = BuildWebHost(args);
// RunSeedMethods(host);
host.Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.Build();
// ReSharper disable once UnusedMember.Local
private static void RunSeedMethods(IWebHost host)
{
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var userManager = services.GetRequiredService<UserManager<ApplicationUser>>();
var roleManager = services.GetRequiredService<RoleManager<ApplicationRole>>();
// DatabaseIdentityInitializer.Init(userManager, roleManager).Wait();
DatabaseIdentityInitializer.CreateDeveloperAccount(userManager, roleManager).Wait();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment