DDDD: event data

I am trying to omit DDDD in the style of Greg Jung .

There is a lot of talk about how to implement DDDD with CQRS + EventSourcing and there are some implementation examples ... and in general this can be quite confusing ...

In the Gregs view, aggregates do not have getters or setters - just state-changing methods that emit the corresponding event.

Basically, an event describes state transitions that occurred in the past. This data describes what has changed.

Some say that this data can be "enriched" with additional data .
Where can this additional data come from ?

i.e. I have User and Usergroup as aggregate roots (they can exist independently, have an identity). User has a method called AddToUsergroup .

 public class User : AggregateRoot { // ... public void AddToUsergroup(Usergroup usergroup) { // validate state RaiseEvent(new UserJoinedUsergroup(this.Id, usergroup.Id)); } // ... } public class Usergroup : AggregateRoot { private string _displayName; // ... public void ChangeDisplayName(string displayName) { // validate state RaiseEvent(new DisplayNameChanged(this.Id, displayName)); } public void Apply(DisplayNameChanged e) { this._displayName = e.DisplayName; } // ... } 

If I would like to enrich an " event with the name of a user group (for debugging reasons or something like this), how would I do it?

  • getters nonexistent
  • user group internal state unavailable

Injection : repositories in User not allowed ( Am I right here?!? >), E.g.

  • Read Side Repository
  • Event Repository

Questions at the bottom:

  • Can Should something like repositories be introduced to combine the roots?
  • If the event only uses the data available through the parameters and the internal state of the population?
  • Should events only contain minimal data describing a state change?

And (a little off topic, but the sample is here)

  • Should AddToUsergroup take Guid instead of the full root placeholder ?

Looking forward to your answers!

Lg
warappa

+7
source share
1 answer

Should some similar repositories be introduced to combine the roots?

No, and in this case there is no need. It may be appropriate to transfer the domain service to the behavioral method in the aggregate, but again it is not necessary in this case.

If an event uses data only through the parameters and internal state of the population?

Yes, the source domain event must be such that it can be easily generated by the aggregate and can be reproduced in a deterministic way.

Should events contain only minimal data describing the state of change?

Yes. However, to meet the requirements of external subscribers, this means that the content enricher enters the game. To send a domain event from outside, it is first transferred to the event store, then you can send in the same tx or have an out-of-process mechanism that publishes events from the outside. At the time of publication from the outside, you usually use a different contract for the message, because subscribers may need more than the actual domain. In this case, you will need the name of the user group. Then the publisher can pull out the name of the user group and put this data into the enriched event. This publisher may have access to the reading model repository for groups of users that would allow him to get a name.

Should AddToUsergroup take Guid instead of a full placeholder?

Yes. The transfer of the entire population may not be possible, and also creates the illusion that something other than an identifier can be used, which should not be.

+5
source

All Articles