문제

I am new to CQRS and confused on how command will write a address change to a customer object

Lets say I have divided customer information into two tables

customer - Domain database

Active Preferred

Customer_Read database

Name,

Address,

Phone,

email

User modifies address of the customer. The address fields are all in read database. there may be 3 or more query friendly tables that is keeping address information.

If I understand the CQRS implementations (sample) Customer Domain (removed Aggregate root) should be publishing event about address change that should be handled by multiple handlers to update each of the table.

How do I implement this when I wont be changing the state of customer object? Do domain have to know that it has address in another database ?

Thank you in advance.

Regards,

The Mar

Update--

After going through more posts on net I am assuming that if the state is not changed by the command no event will be generated to save the domain itself but events will be applied to change the address in query / View Model friendly tables.

도움이 되었습니까?

해결책

You still need to persist some domain data somewhere in the write persistence. This way the address is stored in this persistence store, event is published after changing it.

This way:

  • if there were no change - we can skip publishing the event
  • domain does not need to know anything about objects that may (or may not) be subscribed to his events.

This logic applies to both persistence in relational DBs (MS SQL with NHibernate, for example) and event sourcing approach.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top