Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Sorry, I don't get it. With this approach you describe your aggregate mutations with events, for me is perfect. With this approach you restrict the possible mutations in your domain so you have more control of them. For you what is the issue with the second example? Commented Dec 11, 2020 at 1:22
  • And this is a question, why you say that accountLocked = true; is an invariant? Commented Dec 11, 2020 at 1:26
  • @LeonardoMangano I suppose it isn't an invariant, but rather an effect, which is what lead me to think about it as more closely tied to an Event. To me, there's no inherent problem with the second example. I guess it's more about the driving factors. To me, it's more about the time relationship between the Event being created, and the state change causing that Event. Without having a separate State class, the state would be inside the Aggregate class. When the Aggregate is told to do something, by calling one of its methods, it does something. For me there's a natural tendency for Events to... Commented Dec 11, 2020 at 1:56
  • ... represent things that already happened. Without a separate State class, it seems weird if we publish the event without making the appropriate changes to the Aggregate, which is why the second example feels so strange. It feels like we're saying something happened (the account was locked) before the aggregate reflects that fact (Event is created before Locked flag is set to true). I may have thought of a way to reconcile this in my head, by determining the "decision point" of an Event. I'll see if I can find a good way to explain it in the question. Commented Dec 11, 2020 at 2:00
  • I think your last update is very clear, the event happened when you decided to create it based in a command, after some validations and based in some conditionals. After that event was created (happened) you have lot of reactions like changing the aggregate in memory, then in the DB and then publishing the event. I think this is a good way to think about this Commented Dec 11, 2020 at 2:43