Reputation: 4124
I would like to get a reference to UserManager of Identity, because I would like to create a test user to seed the data.
I get a context:
var context = new MyContext(serviceProvider.GetRequiredService<DbContextOptions<ApiContext>>())
But now I need a reference to UserManager because I need to use it to create a user in my static SeedData class.
I use an Asp.Net Core 2.0.
Is it possible to do it?
Upvotes: 2
Views: 2422
Reputation: 462
I am pretty sure you can use thru constructor injection.
Add Identity to Startup.cs
public class UsersRepository
{
public UsersRepository(UserManager<Users> userManager)
{
_userManager = userManager;
}
public void Foo(){
_userManager.DoSomething();
}
}
It works for me just fine.
Upvotes: 1