1
votes

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
I'm very new to CQRS, but I would said that all commands and queries should be called from the model, isn't it?Steve B
Yes, layers can indeed be considered an anti-pattern. CQRS can help getting rid of layers, aka Lasagna Software (as opposed to Spaghetti Software). Have a look at some alternativ concepts, such as Hexagonal Architecture or the Ports and Adapters pattern.Dennis Traub
@SteveB, please refer linkdevanalyst

1 Answers

2
votes

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.