Domain objects in Commands/Queries ?

206 views
Skip to first unread message

Oğuzhan Eren

unread,
Jul 25, 2016, 10:09:06 AM7/25/16
to DDD/CQRS
When using Webapi/Rest as Adapter (Adapter is infrastructure implementation layer of Hexagonal architecture/port and adapters), is that adapter can reach to domain objects? I use Command-CommandHandler at write and Query-QueryHandler at read side

- Commands can include Domain Objects? or only primitive objects?
- Queries can include Domain objects? or only primitive objects?

If query/command cannot include domain objects, each query handler will convert and validate primitive objects to domain objects, this cause redundant code. (DRY)

On the other hand; if query/commands can include domain objects that will cause serialization issue and code sharing between psyhical bounded context (or microservices)

João Bragança

unread,
Jul 25, 2016, 10:53:56 AM7/25/16
to ddd...@googlegroups.com
This gets asked a lot. Don't put domain objects on the wire! Think about what can happen if you change your value object's internal structure but you haven't upgraded your clients yet.

Yes, in order to write nice decoupled code you will have to write more of it.

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Oğuzhan Eren

unread,
Jul 26, 2016, 1:47:43 AM7/26/16
to DDD/CQRS, joao...@braganca.name
Can we think projections (readmodel, search, ...) as microservices? ( psyhical bounded context) If answer is yes, we shouldn't put domain objects into to domain events and I should never use domain objects except domain and application layer.

But this cause Design Smell: Primitive Obsession at many layer, http://blog.ploeh.dk/2015/01/19/from-primitive-obsession-to-domain-modelling/

25 Temmuz 2016 Pazartesi 17:53:56 UTC+3 tarihinde João Bragança yazdı:

urbanhusky

unread,
Jul 26, 2016, 1:50:13 AM7/26/16
to DDD/CQRS
Why do you want to pass entire objects in commands, when the command should reflect some intent (i.e. an action performed on an aggregate)?
Concerning queries: you could return the domain objects, but maybe you might benefit from using more query-optimised read models (i.e. take CQRS a bit further - but only if it is worth the effort and warranted to do so)

Example: Order aggregate is stored in document database. Writing happens via commands (i.e. aggregate state is loaded from DB, method on aggregate according to command is invoked, save new aggregate state). Queries run against the database (but must never modify the data!). Easiest CQRS implementation.

More extreme: indexes, map/reduce etc. on the aggregate are queried.

João Bragança

unread,
Jul 26, 2016, 4:27:15 AM7/26/16
to ddd...@googlegroups.com
I think you are misunderstanding the point of the article. Note that the author is using a repository to retrieve the User aggregate. The repository interface is a domain service, and should therefore be expressed in domain terms, e.g. value objects.

However, the sample he gives is in no way CQRS, as he is putting the entire User aggregate on the wire.

Igor Berger

unread,
Aug 6, 2016, 11:27:10 PM8/6/16
to DDD/CQRS, joao...@braganca.name
Reply all
Reply to author
Forward
0 new messages