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
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With