gpt4 book ai didi

asp.net - 洋葱架构标识框架

转载 作者:行者123 更新时间:2023-12-04 11:58:10 25 4
gpt4 key购买 nike

我正在关注 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并在其中插入身份表。然后我移动了我的 T4 templateCore.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com