随着 MVC 5 版本的推出,Asp.Net.Identity 位包括 UserManager。实例化可能会变得困惑,我正在尝试使用 Autofac Controller 设置进行添加。
Controller 的构造函数
public LoginController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
}
手动创建新实例:
var controller = new LoginController(UserManager<ApplicationUser>(new ApplicationUserStore<ApplicationUser>(new MyDbContext())));
ApplicationUserStore 类/构造函数:
public class ApplicationUserStore<TUser> : IUserLoginStore<TUser>, IUserStore<TUser>, IDisposable where TUser : ApplicationUser
public ApplicationUserStore(IMyDbContext context)
{
Context = context;
}
我有新的数据库上下文可以正常工作:
builder.RegisterType<MyDbContext>().As<IMyDbContext>();
LoginController 的注册签名是什么?
最佳答案
我不知道 AutoFac,但大胆猜测:
builder.RegisterType<ApplicationUserStore<ApplicationUser>>()
.As<IUserStore<ApplicationUser>>();
builder.RegisterType<UserManager<ApplicationUser>>();
关于asp.net-mvc - 如何将 ASP.NET MVC 5 UserManager 实例与 Autofac 连接起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20623233/