我关注Onion Architecture。而且我正在使用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上执行。这为我创建了身份表。
在我的Infrastructure.Data
项目中,我创建了一个Edmx File
并在其中插入了Identity表。然后我将T4 template
移到了Core.Domain
,在这里我为Partial Class
和其他身份表创建了AppUser
。
// This make my Core.Domain project dependent on `Microsoft.AspNet.Identity`
// Which is a violation.
public partial class AppUser : IdentityUser
{
//My Custom Properties
}
现在我对我在Core中的AppUser
类感到困惑。根据洋葱架构标准,整个层不应该依赖于任何外部库。但在这里我使用'Microsoft.AspNet.Identity'以使我的用户成为身份用户。对此有什么解决方案吗?
答案 0 :(得分:1)
AppUser派生自IdentityUser的问题现在是您的核心项目依赖于它为Asp.Net设计的框架,您的核心项目可能会变得有偏见。你是正确的,核心(即中央)项目应该是平台独立的。
如果您想使用IdentityUser,您可以在WebClient / WebApi项目中定义一个继承自IdentityUser的User实体,并将它们保留在这些表示层中,远离核心。
要将演示文稿用户实体传达到核心,您可以手动将属性映射到核心AppUser,或使用AutoMapper等映射工具
修改强>
包含图表:
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