Search code examples
domain-driven-design

How to ignore events raised in the constructor by loading aggregate roots?


I see that some people raise domain events in the constructor of aggregate roots. https://github.com/szjani/predaddy/blob/4.0/tests/src/predaddy/domain/User.php What is the best way to ignore these events when I load my aggregate root from the database?


Solution

  • I checked several articles in the topic and most of them use factory method for creation and some of them factory or builder patterns. Raising the domain event in the constructor appears to be an anti-pattern. Thanks for the comments, which pointed this out and lead me to the right direction!