In CQRS, should my read side return DTOs or ViewModels?

前端 未结 4 1150
太阳男子
太阳男子 2020-12-23 16:59

I\'m having a debate with my coworkers in the design of the read side of a CQRS application.

Option 1: The application read side of my CQRS applicat

4条回答
  •  既然无缘
    2020-12-23 17:48

    The general advice is one projection per screen (Greg Young) or even one projection per widget (if I understand Udi Dahan correctly).

    To consolidate read models into DTOs that once again have to be mapped into separate views contradicts the whole purpose of an optimized read model. It adds complexity and mapping steps that we tried to get rid of in the first place.

    My advice: Try to get as close as possible to SELECT * FROM ViewSpecificTable [WHERE ...] or something similar if using NoSQL in your thin read layer.

    The concept of Aggregate Roots and their "children" doesn't have too much of an implication on the read side, since these are domain model concepts. You don't want to have a domain model on the read side, it only exists on the write side.

    UI platform-specific transformation as mentioned by Mohamed Abed should be done in the UI layer, not in the read model itself.

    Long story short: I'd opt for option 2. To not confuse it with a platform-specific ViewModel, I'd rather call it ReadModel but have one per view anyway.

提交回复
热议问题