Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type IUserStore`1 does not have an accessible constructor

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

like image 436
Sebastian Widz Avatar asked Oct 02 '22 03:10

Sebastian Widz


1 Answers

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();
like image 190
Randy supports Monica Avatar answered Oct 05 '22 06:10

Randy supports Monica