The type IUserStore`1 does not have an accessible constructor

谁都会走 提交于 2019-12-22 06:52:19

问题


I want to setup MVC5 application with Unity 3. I created a default web mvc5 application from a standard template then add unity

When I am accessing the Register action in AccountController I get the following exception:

The type IUserStore`1 does not have an accessible constructor.

from this post How to add MVC 5 authentication to Unity IoC? I know the problem is that Unity selects the constructor with longer parameter list.

The solution is to register the Account controller to be used with default constructor the following way:

container.RegisterType<AccountController>(new InjectionConstructor());

What I would like to do is to register it in the configuration file no in the code Is it possible to do the same in web.config?

Best Regards, Sebastian


回答1:


You can configure Unity using XML configuration. In your case it would look something like this:

<configSections>
  <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>    

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">    
  <container>
    <register type="MyApp.AccountController, MyApp">
      <constructor />
    </register>
   </container>
</unity>

And then you need to explicitly load the configuration:

IUnityContainer container = new UnityContainer();
container.LoadConfiguration();


来源:https://stackoverflow.com/questions/22846327/the-type-iuserstore1-does-not-have-an-accessible-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!