Rya*_*anW 3 asp.net-mvc dependency-injection autofac asp.net-mvc-5
随着MVC 5的发布,Asp.Net.Identity位包括UserManager.实例化可能会变得混乱,我正在尝试添加Autofac控制器设置.
控制器的构造函数
public LoginController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
}
Run Code Online (Sandbox Code Playgroud)
手动创建新实例:
var controller = new LoginController(UserManager<ApplicationUser>(new ApplicationUserStore<ApplicationUser>(new MyDbContext())));
Run Code Online (Sandbox Code Playgroud)
ApplicationUserStore类/构造函数:
public class ApplicationUserStore<TUser> : IUserLoginStore<TUser>, IUserStore<TUser>, IDisposable where TUser : ApplicationUser
public ApplicationUserStore(IMyDbContext context)
{
Context = context;
}
Run Code Online (Sandbox Code Playgroud)
我有新的db上下文正常工作:
builder.RegisterType<MyDbContext>().As<IMyDbContext>();
Run Code Online (Sandbox Code Playgroud)
LoginController的注册签名是什么?
我不知道AutoFac,但猜测:
builder.RegisterType<ApplicationUserStore<ApplicationUser>>()
.As<IUserStore<ApplicationUser>>();
builder.RegisterType<UserManager<ApplicationUser>>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3612 次 |
| 最近记录: |