问题描述
我不知道是否有人跑进了我与试图移动 ApplicationUser
成模型项目(所有其他型号驻留包括与用户表中的)遇到的问题
I wonder if someone ran into the issue that I am having with trying to move ApplicationUser
into Models project (where all other models reside including the ones related to Users table).
我的测试MVC 5解决方案包括一个Web项目和两个类库:一个用于数据访问层(DAL),另一个用于模型。我引用AspNet.Identity.EntityFramework在所有三个项目。
在我的DAL类我实现了存储库模式和的UnitOfWork。扩展的UnitOfWork IdentityDbContext< ApplicationUser>
。 ApplicationUser:IdentityUser是模型类库
My test MVC 5 solution consists of a web project and two class libraries: one for data access layer (DAL) and the other for Models. I references AspNet.Identity.EntityFramework in all three projects.In my DAL class I implement Repository pattern and a UnitOfWork. UnitOfWork extends IdentityDbContext<ApplicationUser>
. ApplicationUser : IdentityUser is in Models class library.
在我的Web项目的UnitOfWork使用Autofac DI实例化。
对于经常控制器我定义从控制器继承并采取IUnitOfWork作为构造函数的参数的基类。所有控制器从我的自定义基本控制器继承。
我遇到了一个问题,的AccountController
。它有两个构造函数:一个无参数,似乎实例 ApplicationDbContext
,其他需要的UserManager作为参数。
In my web project UnitOfWork is instantiated using Autofac DI.For regular controllers I defined a base class that inherits from Controller and takes IUnitOfWork as a parameter in the constructor. All controllers inherit from my custom base controller. I ran into a problem with AccountController
. It has two constructors: one with no parameters that seems to instantiate ApplicationDbContext
, the other takes UserManager as a parameter.
无参数的构造函数给了我最悲伤的。我试了很多东西:让的AccountController
从我的自定义基本控制器继承,然后尝试从Controller类继承它。在最好的,我在做我的解决方案编译成功,但是当我测试应用程序并填写用户登记表,我得到'对象不是实例的消息。当我调试我看到,在第二个构造的AccountController
被调用,但的UserManager
为空在那里。
The parameter-less constructor gives me most of the grief. I tried many things: make accountcontroller
inherit from my custom base controller, then try to inherit it from the Controller class. At best I succeed in making my solution compile but when I test the app and fill out user Registration form I get 'Object is not instantiated' message. When I debug I see that the second constructor in AccountController
gets called but UserManager
is null there.
任何想法?我真的AP preciate别人的聪明投入这一点。
Any ideas? I would really appreciate somebody's brainy input into this.
推荐答案
看看在。该项目从Web应用程序分离出来ASP.NET身份并把<一个href=\"https://simplesecurity.$c$cplex.com/SourceControl/latest#AspNetIdentity/SimpleSecurity.AspNetIdentity/Entities/ApplicationUser.cs\">ApplicationUser到组件分离从Web应用程序。该项目还具有使用SimpleMembership一个版本。对于ASP.NET身份看在AspNetIdentity文件夹中。为安全功能的组件处于AspNetIdentity / SimpleSecurity.AspNetIdentity和基准网络应用程序是在AspNetIdentity / SimpleSecurity.AspNetIdentity / RefApp
Take a look at the SimpleSecurity Project. This project decouples ASP.NET Identity from the web application and puts ApplicationUser into an assembly separate from the web application. This project also has a version that uses SimpleMembership. For ASP.NET Identity look in the AspNetIdentity folder. The assembly for the security functions is in AspNetIdentity/SimpleSecurity.AspNetIdentity and the reference web application is in AspNetIdentity/SimpleSecurity.AspNetIdentity/RefApp.
这篇关于如何移动MVC 5 IdentityModels.cs成一个单独的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!