Situation:
To work with domain events, Jimmy Bogart proposed a method for storing events in aggregates.
This, from my point of view, is a very convenient approach. However, what about the case of a domain event in the domain service?
Domain Service should not have a state (stateless). In this case, in theory, the IDispatcher event dispatcher must be injected into the constructor of such a service.
Question:
To avoid introducing into the domain service of the event dispatcher, the suggested alternative approaches are correct:
- Saving in the domain service of events of the last operation. However, this will violate the principle of stateless for the domain service.
- Return the list of events from the service method based on the results of the operation (in the return method or in another way, depending on the capabilities of the programming language).