在Hexagonal Architecture asp.netcore webapi中不将域耦合到基础结构层



我使用的是Hexagonal Architecture,这是一个扩展asp.netcore身份的应用程序用户实体,位于域层(因此将域耦合到基础结构层(,以及技能实体(一个应用程序用户可以拥有多种技能,一项技能可以属于多个应用程序(,您对应用程序用户作为域实体有什么想法?我们可以使用什么方法将其保留在域中,但同时不将该层与基础架构层耦合?

域的全部意义在于它不知道特定于技术的细节,例如asp.net核心的身份。

因此,从这个角度来看,ApplicationUser(正如您所描述的(实际上属于基础结构层,因此不属于域层。

现在,您可以使用一个简单的OOP模式将域和基础设施解耦,例如:

// Domain layer (abstraction)
interface IIdentity
{
string Email { get; }
}
// Infrastructure layer (implementation details)
class AspNetCoreIdentity : IIdentity
{
public AspNetCoreIdentity(ApplicationUser user)
{
this.User = user;
}
private ApplicationUser User { get; }
public string Email => this.User.Email;
}

希望有帮助。。。

最新更新