I have web app using asp.net core 2.0 with identity and entity framework core. I am trying to create few users after DB is created. I created DbInitializer class which is called from Program.Main()
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<ApplicationDbContext>();
DbInitializer.Initialize(context);
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred while seeding the database.");
}
}
host.Run();
}
Problem is that I cannot access UserManager whit right PasswordHasher in my class. I try this answer, and I created new UserManager like this
var store = new UserStore<ApplicationUser>(context);
var hasher = new PasswordHasher<ApplicationUser>();
var manager = new UserManager<ApplicationUser>(store, null, hasher, null, null, null, null, null, null);
await manager.CreateAsync(user, "password");
And then I create user. User is created and I can see him in DB, problem is that I cannot log in with given password. I think the problem is that I created new PasswordHasher. How can I access UserManager that is used in application?..