ViewModel location when doing CQRS

前提是你 提交于 2019-12-08 03:13:50

问题


Suppose you have a layered project divided into the Presentation Layer, the Business Layer and the Data Access Layer. If you were using CQRS, you would be doing queries directly from the Data Access Layer into the Presentation Layer and bypassing the Business Layer.

In that case, if you are using ViewModels in your presentation layer, then your Data Access Layer would need reference to the Presentation Layer to return data in terms of the ViewModels in the presentation layer. Wouldn't that be anti-pattern ?

A similar question exists here - Models, ViewModels, DTOs in MVC 3 application

But if you are doing CQRS you will not be mapping between your ViewModel and Domain object as mentioned in the answer, since you are bypassing your Domain/Business layer Then where should you place your ViewModels ?


回答1:


As far as i understand CQRS you will get DTOs (DataTransferObjects) from the query side (aka. DataAccessLayer) that gets passed to the UI (PresentationLayer).

Theses DTO can directly be used as ViewModels for Views, if they provide all necessary data for the View, or can be aggregated with other DTOs in an ViewModel. I think it depends on the data that is presented in the View.

To answer your question: ViewModels are part of the PresentationLayer.



来源:https://stackoverflow.com/questions/11466065/viewmodel-location-when-doing-cqrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!