Open webdevilopers opened 2 years ago
There is an extension by @vaniocz @nixbody @maryo: https://github.com/vaniocz/doctrine-domain-events
I guess flushing on the entity manager and publishing the domain event should happen in the same transaction?
As documented:
The event is dispatched at the end of transaction once your entity has been flushed and all the changes are projected into database so it is possible to both perform database queries over the changes as well as cancel the transaction.
Source: https://github.com/vaniocz/doctrine-domain-events#raising-domain-events
Currently we use Prooph Event Sourcing for our Aggregate Roots. Since the Prooph Service Bus was deprecated we use the Symfony Messenger instead.
We have some legacy projects using Doctrine Entities. We don't want to use Event Sourcing. But we would like to publish Domain Events from the Entity to the Messenger Bus.
Has anybody implemented a Domain Publisher using Doctrine Event Subscribers or Lifecycle Callbacks for instance? I guess flushing on the entity manager and publishing the domain event should happen in the same transaction?