I have a question regarding updating multiple aggregates in a single transaction using the JOliver Event Store . As far as I understand, each unit should have its own stream of events. Now, although many command handlers will load only one aggregate and update only this aggregate (i.e., save events for these aggregates), I can imagine that there will be command handlers that need to update several aggregates. And of course, I would like to do it in a transactional way.
However, I do not see how to do this with the event repository. Events are stored by calling CommitChanges()in the event stream. If we have several aggregates for updating, they will have several streams of events and, therefore, several calls to CommitChanges(). The only way to make a transaction is to wrap it in TransactionScope, but that doesn't make much sense, since the underlying storage technology may not support transactions. So I end up with this code, which is definitely not what I'm looking for:
Guid aggregateGuid1 = Guid.NewGuid();
Guid aggregateGuid2 = Guid.NewGuid();
Guid commitGuid = Guid.NewGuid();
var stream = store.OpenStream(aggregateGuid1, 0, int.MaxValue);
stream.Add(new EventMessage() { Body = new MonitorDisabled { MonitorGuid = aggregateGuid1, User = "A" } });
stream.CommitChanges(commitGuid);
stream = store.OpenStream(aggregateGuid2, 0, int.MaxValue);
stream.Add(new EventMessage() { Body = new MonitorEnabled { MonitorGuid = aggregateGuid2, User = "B" } });
stream.CommitChanges(commitGuid);
It makes me feel like I totally don’t understand how to use the Event Store. Can anyone help me here? Many thanks!
source
share