Usm*_*lid 6 .net asp.net onion-architecture asp.net-web-api asp.net-identity
我正在关注洋葱架构。并且我正在使用 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
Run Code Online (Sandbox Code Playgroud)
我已经复制了 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
}
Run Code Online (Sandbox Code Playgroud)
现在我对AppUserCore 中的 Class感到困惑。根据洋葱架构标准,这整个层不应该依赖于任何外部库。但在这里我使用“Microsoft.AspNet.Identity”以使我的用户成为身份用户。有什么解决办法吗?
从 IdentityUser 派生的 AppUser 的问题是现在您的核心项目依赖于它为 Asp.Net 设计的框架,在那里您的核心项目可能会产生偏差。您认为核心(即中央)项目应该独立于平台,这是正确的。
如果您想使用 IdentityUser,您可以在 WebClient/WebApi 项目中定义一个 User 实体,该实体继承自 IdentityUser 并将它们保留在这些表示层中,远离核心。
要将演示用户实体传送到核心,您可以手动将属性映射到核心 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2300 次 |
| 最近记录: |