我正在关注洋葱架构 http://jeffreypalermo.com/blog/the-onion-architecture-part-1/。我正在使用 ASP.NET Identity Framework。
这是我的项目结构:
1-Core
- Domain Classes //It contains my T4 template classes
-- AppUser //It is Identity User.
- Repository Interfaces
- Service Interfaces
2-Infrastructure
- Data //It contains my edmx file, I am using Db First approach.
- Dependency Injection
- Repository Interfaces Implementation
- Service Interfaces Implementation
3-WebApi
- Web Api Project
4-WebClient
- My AngularJs App
5-Test
- Test Project
我已复制 ASP.NET Identity 表的脚本并在我的 SQL Server 上执行。它为我创建了身份表。
In my Infrastructure.Data
项目,我创建了一个Edmx File
并在其中插入身份表。然后我移动了我的T4 template
to Core.Domain
,我在这里创建了Partial Class
for my AppUser
和其他身份表。
// This make my Core.Domain project dependent on `Microsoft.AspNet.Identity`
// Which is a violation.
public partial class AppUser : IdentityUser
{
//My Custom Properties
}
现在我对我的事情感到困惑AppUser
Core 中的类。根据洋葱架构标准,整个层不应依赖于任何外部库。但在这里我使用“Microsoft.AspNet.Identity”以使我的用户成为身份用户。有什么解决办法吗?
从 IdentityUser 派生的 AppUser 的问题是现在您的核心项目依赖于它为 Asp.Net 设计的框架,在那里您的核心项目可能会产生偏差。您认为核心(即中央)项目应该独立于平台,这是正确的。
如果您想使用 IdentityUser,您可以在 WebClient/WebApi 项目中定义一个 User 实体,该实体继承自 IdentityUser 并将它们保留在这些表示层中,远离核心。
要将演示用户实体传送到核心,您可以手动将属性映射到核心 AppUser 或使用映射工具,例如自动映射器 http://automapper.org/
Edit
包含图:
1-Core
- Domain Classes
-- AppUser
- Repository Interfaces
- Service Interfaces
2-Infrastructure
- Data //It contains my edmx file, I am using Db First approach.
- Dependency Injection
- Repository Interfaces Implementation
- Service Interfaces Implementation
3-WebApi
- Web Api Project
- Models
ApiUser : *(Inherits Api Identity framework)*
4-WebClient
- My AngularJs App
- Models
WebUser : *(Inherits IdentityUser)*
5-Test
- Test Project
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)