我想在程序的种子方法中创建一个新用户但是如何调用CreateAsync?
public class DbInitializer
{
private readonly UserManager<ApplicationUser> _userManager;
public DbInitializer(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public static void Initialize(IApplicationBuilder app)
{
OneDbContext context = app.ApplicationServices.GetRequiredService<OneDbContext>();
context.Database.EnsureCreated();
//If there are no users, create a test user
if (!context.Users.Any())
{
var user = new ApplicationUser { UserName = "test", Email = "test@test.com" };
var result = _userManager.CreateAsync(user, "test");
}
错误CS0120:非静态字段,方法或属性需要对象引用&#39; DbInitializer._userManager&#39;