【发布时间】:2017-01-13 11:43:21
【问题描述】:
我在 UserManager 类中解析 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>();
有错误:
无法解析服务类型 'MyContext' 同时 尝试激活“UserManager”。
有谁知道问题出在哪里?
【问题讨论】:
-
你有一个错字,你的
MyContext_context是togheter。改成MyContext _context -
它的错字只是在这里因为格式,但感谢编辑:)
标签: c# asp.net dependency-injection asp.net-core