作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在关注 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
Infrastructure.Data
项目,我创建了一个
Edmx File
并在其中插入身份表。然后我移动了我的
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
}
AppUser
感到困惑Core 中的类。根据洋葱架构标准,这整个层不应该依赖于任何外部库。但在这里我使用“Microsoft.AspNet.Identity”以使我的用户成为身份用户。有什么解决办法吗?
最佳答案
从 IdentityUser 派生的 AppUser 的问题现在是您的核心项目依赖于它为 Asp.Net 设计的框架,在那里您的核心项目可能会变得有偏见。核心(即中央)项目应该与平台无关,这是正确的。
如果您想使用 IdentityUser,您可以在继承自 IdentityUser 的 WebClient/WebApi 项目中定义一个 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
关于asp.net - 洋葱架构标识框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30729139/
我无法理解六边形(端口适配器)架构中依赖的含义。 Here他们有漂亮的照片。我没有看到的是与 n 层结构有什么区别(实现)。 在 onion/hex 架构中,inner 层应该独立于outer 层,但
我是一名优秀的程序员,十分优秀!