Event Sourcing and Lists

148 views
Skip to first unread message

Polemann

unread,
Nov 26, 2010, 3:11:55 PM11/26/10
to DDD/CQRS
I've got a list of Shipping Rules (a rule is its own aggregate). I'm
trying to load these rules and apply them to another Aggregate Order.

I'm using Event Sourcing and I'm not 100% clear how to reload the list
of rules. There's no 'collection of rules' aggregate in my domain and
I don't really want to use the read model to reload the identifiers
and then load the rules one at a time from the database.

does anyone have any similar experiences or does anyone have general
recommendations on how to mix ES and 3NF data loading.

Chris Nicola

unread,
Nov 30, 2010, 1:37:26 PM11/30/10
to DDD/CQRS
I have an old post here where I did something very similar (http://
groups.google.com/group/dddcqrs/browse_thread/thread/2ba20ecfdf585bd5/
b2855c957e229846). In it there is a data set that is part of the
state of the aggregate root.

Funny enough the aggregate root also has a list of rules. I
considered rules to not be their own aggregate, since we can't have a
rule without a the program existing. So you need to consider if, from
the perspective of you business domain, a rule is really its own
root.

From there it is fairly straight forward to populate the list from
events like AddNewRule, RemoveRule, etc.

Otherwise you are entering the topic of interaggregate communication.
I've seen this handled two ways:

1. Expose some state in your aggregates so you can interact with them
at the command level. This violates the tell-don't-ask approach of
CQRS though, but it may offer you a simple solution at the risk of
polluting your domain.

2. Use some form of interaggregate messaging via the domain events.
This seems to be the prefered and 'pure' approach. I know that they
are working on having something built-in for this in nCQRS but it
isn't done yet.

I will agree I have found the concepts of inter-aggregate dependencies
and communication in CQRS to be a challenge as well.

Chris

Suirtimed

unread,
Nov 30, 2010, 1:40:32 PM11/30/10
to DDD/CQRS
If I had an ES system up and running, I wouldn't want to mix 3NF data
loading. I would look back at the domain(s) and make sure I had good/
clear boundaries. Do all of the rules need to be applied to the
order? You may need to have a rules collection as an aggregate root
in a different domain if that is the case. You could have one domain
that manages the rules (newRuleAdded, ruleDeActivated, etc...) and a
different domain that applies the rules to an order
(rulesAppliedToOrder or orderReadyForShipping).
Reply all
Reply to author
Forward
0 new messages