-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Side Effects: Where to put and how to handle them #24
Comments
I'm not so sure about the conclusion to do side-effects in the ProcessManager any more. Either you don't register all your ProcessManagers during replay - then they may for example not emit Events themself (which is a trait I think is quite useful) - or you end up with the same problem as before. My conclusion currently is one of two things:
|
What do you mean with side effect, can you provide an example and how you would suggest to solve it? |
Prime example: Send registration confirmation email You don't want that to happen every time you replay your aggregate. As to suggestion, see above, but I'm fully open to other ideas |
Thanks for the examples!
I wouldn't send those from the aggregate. And if so, only in the handling part like so: class SomeAggregate
{
public function doSomething()
{
// validate
$this->recordThat(new SomethingHasHappened());
$this->someService->sideEffect();
} This is not very error tolerant though, so I usually put those in a separate event listener: class RegistrationEventListener
{
public function whenSomethingHasHappened(SomethingHasHappened $event)
{
$this->someService->sideEffect();
} |
Yeah, Aggregate is actually a big design-error - it totally breaks single responsibility and also might blow up aggregate consistency (in case the side-effect errors out). So the solution indeed is to have it in some EventListener (or rather ProcessManager as I described it in #8 (comment)), but as said above, for those you still need to somehow make it explicit that this EventListener should not be registered during replay. So you end up with something like |
None of the EventListeners should ever be retriggered. BTW: A |
I close this for now as we have everything in place (except documentation and good example) to deal with side-effects: It's just an |
Side-Effects are an integral part of nearly every application. Where to put them has therefore become a major concern in current software architectures that allow time-traveling:
http://jaysoo.ca/2016/01/03/managing-processes-in-redux-using-sagas/
reduxjs/redux#1528
http://danielwhittaker.me/2015/03/31/how-to-send-emails-the-right-way-in-a-cqrs-system/
I think this is something that we need to discuss and find a good solution for that works with replaying.
The text was updated successfully, but these errors were encountered: