Thanks for the response, just to get it right, by “use a domain service that maintains a consistent…
John Doe
1

John Doe, yes, subscribing to UserCreatedEvent would be fine if your projections are consistent with your event store. Otherwise you’d have to use the service to reserve usernames as well. As for when this code is run, it would flow as follows.

  1. Command is dispatched.
  2. Command handler loads aggregate.
  3. Behavior of aggregate is invoked.
  4. Validation is run (including usage of the domain service).
  5. Event is created.
  6. Event is applied to aggregate.
  7. Event is stored and dispatched.
Show your support

Clapping shows how much you appreciated Daniel Little’s story.