【发布时间】:2015-11-06 19:47:30
【问题描述】:
还是应该在顶层(客户端 UI)? 当使用洋葱架构(ASP.Net MVC)时,我应该将我的视图模型与我的所有域实体放在核心。就像下图一样?
我的问题是 - 如果是,那么当我将视图模型从我的服务传递给我的客户端时,客户端(顶层)是否依赖于核心层,核心层向下两层并且不会中断每一层的整个依赖关系只与它下面的层对话?
当我有一个视图模型(在表示层中)需要引用域层(向下两层)中的实体时会发生什么,这不会破坏仅引用正下方层的洋葱架构。
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; }
}
【问题讨论】:
-
恕我直言,视图模型属于视图。每个 UI 都有一组不同的视图模型。有时它们可能类似于域模型,但域模型代表一个概念,而视图模型只是 UI 的 DTO。
标签: asp.net-mvc dependency-injection n-tier-architecture onion-architecture