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

前端 未结 4 1175
太阳男子
太阳男子 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:49

    A read model is a projection of the write model. It's there to fulfill a specific purpose. In your case that seems providing view models to your MVC controllers. As such, why go thru the trouble of mapping DTO's to Viewmodels? The only reason I could think of was that the benefit of having two separate read models might not outweigh their maintenance cost. But do consider that "merging" read models for the purpose of "reuse" and "lowering maintenance costs" increases complexity for the developer (Can I change this table? Hmmm, I now have two (or more) consumers I have to take into account - smells a bit like database integration all over again).

    Just my thoughts.

提交回复
热议问题