Snæ*_*ørn 14 c# onion-architecture asp.net-identity
我正在尝试在我的ASP.NET MVC 5解决方案中实现Identity 2.0,该解决方案遵循洋葱架构.
我有一个ApplicationUser核心.
namespace Core.DomainModel
{
public class ApplicationUser {...}
}
Run Code Online (Sandbox Code Playgroud)
在我的数据访问层中,我正在使用实体框架6.1,我的上下文源于IdentityDbContext此处,并且在此处存在问题.ApplicationUser需要从中衍生出来Microsoft.AspNet.Identity.EntityFramework.IdentityUser
namespace Infrastructure.DAL
{
public class TestContext : IdentityDbContext<ApplicationUser> {...}
}
Run Code Online (Sandbox Code Playgroud)
我的域名模型不应该引用Microsoft.AspNet.Identity.EntityFramework违背洋葱的想法.
什么是好的解决方案?
您可以从 Core 命名空间继承 IUser,用户管理器会很高兴。您需要将 IUserStore 替换为您自己的实现。然后初始化用户管理器,如下所示:
new UserManager<ApplicationUser>(new YourNameSpace.UserStore<YourApplicationUser>()))
Run Code Online (Sandbox Code Playgroud)