【发布时间】:2013-07-16 22:37:39
【问题描述】:
我使用最新的 ASP.NET 和 Web Tools 2013 Preview Refresh (1.0.0-beta1) 在 Visual Studio 2013(预览版)中创建了一个新的 MVC5 应用程序。我注意到 IdentityConfig.cs 连同现在是框架一部分的用户模型一起消失了。并且 IdentityStoreManager 是在默认 AccountController 中与 IdentityAuthenticationManager 一起引入的。
当我构建并运行标准项目时,一切正常!到目前为止一切顺利,是的!
然后我从 Nuget 安装 Unity。我拉 Unity 和 Unity.MVC(都是 3.0.1304.0 版本)。安装这些包会导致添加 3 个引用和 2 个项目文件(UnityConfig.cs 和 UnityMVCActivator.cs)。我没有触摸任何文件并尝试运行网络应用程序。主页显示很好,但是当我转到“注册”或“登录”页面时出现错误。使用新 Identity 模型的 AccountController 会抛出以下异常(已修改):
IIdentityStoreContext 类型没有可访问的构造函数。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
[ResolutionFailedException: 依赖解析失败,type = "Teamster.Web.Controllers.AccountController", name = "(none)"。 异常发生时:解决时。
异常是:InvalidOperationException - IIdentityStoreContext 类型没有可访问的构造函数。
发生异常时,容器为:
正在解决 Teamster.Web.Controllers.AccountController,(无) 解析构造函数 Teamster.Web.Controllers.AccountController(Microsoft.AspNet.Identity.EntityFramework.IdentityStoreManager storeManager, Microsoft.AspNet.Identity.EntityFramework.IdentityAuthenticationManager authManager) 的参数“storeManager” 解决 Microsoft.AspNet.Identity.EntityFramework.IdentityStoreManager,(无) 解析构造函数 Microsoft.AspNet.Identity.EntityFramework.IdentityStoreManager 的参数“上下文”(Microsoft.AspNet.Identity.IIdentityStoreContext 上下文) 解决 Microsoft.AspNet.Identity.IIdentityStoreContext,(无) ]
AccountController 有一个无参数的构造函数,但正如例外所说,AccountControllers 构造函数中使用的 IIdentityStoreContext 是统一的问题。 IIdentityStoreContext 在 Identity 框架中。
我该如何解决这个问题,是否可以通过某种方式配置 Unity 容器来解决这个问题?
为了清楚起见,这里是默认的 AccountController ctors。:
public AccountController()
{
IdentityStore = new IdentityStoreManager();
AuthenticationManager = new IdentityAuthenticationManager(IdentityStore);
}
public AccountController(IdentityStoreManager storeManager, IdentityAuthenticationManager authManager)
{
IdentityStore = storeManager;
AuthenticationManager = authManager;
}
【问题讨论】:
标签: asp.net-mvc unity-container visual-studio-2013 asp.net-identity