Dispatching AR version together with its event in JO's CommonDomain

183 views Asked by At

I'm looking for the right way of communicating the current version of my Aggregate to the Read Model. Currently the only possibility I see is to do the following:

public class Child : AggregateBase
{
    ...

    public void ChangeName(string firstName, string lastName)
    {
        RaiseEvent(new ChildNameChanged(Id, Version + 1, firstName, lastName));
    }

    ...
}

I don't like it because I think the Aggregate should dispatch the AR version automatically to all the read side event handlers.

Are there other ways I could do this?

1

There are 1 answers

2
Mikael Östberg On BEST ANSWER

Have a look at this gist from JOliver himself: https://gist.github.com/1311195

Basically what he does is that he attach the version as a header in the dispatched message instead. You don't want to add stuff like that to your events. The events should be kept focusing on the business.