我在UserManager
类中解决DbContext
问题。ASP.NET核心解析服务中的DbContext
这里是UserManager
类:
public class UserManager : IUserManager
{
private readonly MyContext _context;
public UserManager(MyContext context)
{
_context = context;
}
}
我DbContext
类:
public class MyContext: DbContext
{
public DbSet<User> Users { get; set; }
}
启动:
services.AddDbContext<MyContext>(options =>
options.UseSqlServer(Configuration["database:connectionString"]));
//....
services.AddScoped<IUserManager, UserManager>();
有errror:
无法解析 'MyContext'类型的服务,而 尝试激活'UserManager'。
有谁知道问题在哪里?
你的'MyContext_context'是一个输入错误的地方。将它改为'MyContext _context' – Bojje
它的错字只是在这里格式化的cuz,但是感谢编辑:) – miechooy