或者它们应该位于顶层(客户端 UI)? 当使用洋葱架构(ASP.Net MVC)时,我应该将 View 模型与所有域实体放在核心位置。就像下图一样?
我的问题是 - 如果是,那么当我将 View 模型从我的服务传递给我的客户端时,客户端(顶层)是否不依赖于核心层,核心层向下两层,这不会破坏整个依赖关系,每一层只与它下面的层对话?
当我有一个 View 模型(在表示层中)需要引用域层(向下两层)中的实体时会发生什么,这不会破坏仅引用直接下面的层的洋葱架构。
public class YogaSpaceListViewModel
{
// YogaSpaceResults is in the domain layer two layers down
public IPagedList<YogaSpaceResults> YogaSpaces { get; set; }
public string LocationResults { get; set; }
}
// this is in the domain layer with all my other entities
// this is being filled by entity framework in the DAL, which I'm calling from the service layer.
public class YogaSpaceResults
{
public string Title { get; set; }
public string Summary { get; set; }
public DateTime Date { get; set; }
public DbGeography LocationPoints { get; set; }
}
最佳答案
它从外到内工作,因此,客户端了解服务,反之亦然,服务了解域模型,反之亦然。
所以你是对的,如果你把 ViewModel 放在客户端,服务将如何知道这一点?嗯..在这种情况下,您谈论的是应用程序服务而不是域服务,因为它们使用通用语言服务于域模型,而 ViewModel 不应该成为其中的一部分。 应用程序服务应该位于客户端和域模型之间的应用程序层,它们可以协调其他服务和存储库之间的操作。这就是为什么我会说你的 ViewModel 应该位于应用程序层。
关于asp.net-mvc - 我的 View 模型应该以我的域实体为洋葱架构的核心吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31995067/