How to add MVC 5 authentication to Unity IoC?

前端 未结 2 750
执笔经年
执笔经年 2020-12-14 17:46

I\'m currently working on implementing the new ASP.NET MVC 5 out-of-the box authentication into my application. However when using Unity as my IoC, I cannot use any portion

相关标签:
2条回答
  • 2020-12-14 18:12

    Because you have two constructors on your controller, unity will pick up the one with longer parameter list, the latter. It requires the UserManager to be injected.

    Although you haven't listed it here, I suspect is has an only constructor that requires the IUserStore. Unity tried to resolve it and can't find any constructor it could use directly or resolve its parameters.

    0 讨论(0)
  • 2020-12-14 18:12

    I agree with Wiktor.

    You could register the parameterless constructor with Unity though and stop it taking the longer parameter by doing this:

    container.RegisterType<AccountController>(new InjectionConstructor());
    
    0 讨论(0)
提交回复
热议问题