随着MVC 5的发布,Asp.Net.Identity位包括UserManager.实例化可能会变得混乱,我正在尝试添加Autofac控制器设置.
控制器的构造函数
public LoginController(UserManageruserManager) { UserManager = userManager; }
手动创建新实例:
var controller = new LoginController(UserManager(new ApplicationUserStore (new MyDbContext())));
ApplicationUserStore类/构造函数:
public class ApplicationUserStore: IUserLoginStore , IUserStore , IDisposable where TUser : ApplicationUser public ApplicationUserStore(IMyDbContext context) { Context = context; }
我有新的db上下文正常工作:
builder.RegisterType().As ();
LoginController的注册签名是什么?
我不知道AutoFac,但猜测:
builder.RegisterType<ApplicationUserStore<ApplicationUser>>() .As<IUserStore<ApplicationUser>>(); builder.RegisterType<UserManager<ApplicationUser>>();