Architecture 在何处构建复杂对象、业务层或控制器?

Architecture 在何处构建复杂对象、业务层或控制器?,architecture,Architecture,假设我们有一个网页,应该有一个帖子集(标题,日期)和一个帖子列表(标题,正文) 我可以可视化视图模型,如: public class PostCollectionViewModel { public PostCollectionHeader PostCollectionHeader {get;set;} public List<Post> Posts {get;set;} } 公共类PostCollectionViewModel { 公共PostCollectionHead

假设我们有一个网页,应该有一个帖子集(标题,日期)和一个帖子列表(标题,正文)

我可以可视化视图模型,如:

public class PostCollectionViewModel
{
  public PostCollectionHeader PostCollectionHeader {get;set;}
  public List<Post> Posts {get;set;}
}
公共类PostCollectionViewModel
{
公共PostCollectionHeader PostCollectionHeader{get;set;}
公共列表发布{get;set;}
}

我应该调用两个业务层方法来填充这两个视图模型属性,还是应该使用一个业务层方法来返回带有post的post集合?

如果将查询与命令分离(命令-查询分离),您可以有一个特定的查询,它通过一个请求返回您所需的内容——不多也不少。此查询可以绕过业务层(从而避免不必要的开销),直接与数据库进行对话。参见示例