类型IUserStore`1不具有访问构造 [英] The type IUserStore`1 does not have an accessible constructor

查看:364
本文介绍了类型IUserStore`1不具有访问构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Unity 3设置MVC5应用。
我创建了一个默认Web应用mvc5从一个标准模板然后添加统一

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

当我在访问中的AccountController动作注册我得到以下异常:

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

该型IUserStore`1不具有可访问的构造函数。

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

从这个职位如何MVC 5认证添加到Unity国际奥委会?我知道这个问题是统一选择较长参数列表的构造。

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());

我想这样做的是在配置文件中的code无注册它
是否有可能做同样在web.config中?

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

推荐答案

您可以使用XML配置配置统一。你的情况,它会是这个样子:

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();

这篇关于类型IUserStore`1不具有访问构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆