c# - CQRS: Class Redundancy and passing DTO to Domain -
my cqrs application has complex domain objects. when created, properties of entity directly specified user,
createfoocommand has 15 properties.
foocreatedevent has 15 properties, because need entity properties on read-side.
as command parameters must dispatched domain object , foocreatedcommand should not passed domain,
there manual mapping createfoocommand domain.
as domain should create domain event,
that mapping domain foo properties foocreatedevent.
on read side, use dto represent structure of foo stored within read-model.
so event handler updating read-side introduces mapping event parameters dto.
to implement simple business case, have
- two redundant classes
- three mappings of same properties
i thought getting rid of command/event arguments , push dto object around, imply domain can receive or create dto , assign event.
sequence:
rest controller --command+dto--> command handler --dto--> domain --(event+dto)--> event handler
any ideas making cqrs less implementation pain?
i see following options:
create immutable dto class
foodetails
used bothcreatefoocommand
,foocreatedevent
injecting in constructor; type hint aggregate method againstfoodetails
; examplenew createfoocommand(new foodetails(prop1, prop2, ...))
create immutable base class
foodetails
inherited bothcreatefoocommand
,foocreatedevent
, type hint aggregate method againstfoodetails
completely change style , use style promoted cqrs.nu in commands sent directly aggregates; aggregates have command methods
fooaggregate::handle(createfoocommand command)
; use style lot.
Comments
Post a Comment