Reputation: 1048
Having an MVC system, is it better to trigger events in the controller or in the services that are injected in has dependencies?
Eg.
class MyController
{
$brainStorage->store($yellowBrain);
$EventDispatcher->dispatch(new BrainCreatedEvent($yellowBrain));
...
Or should be the storage service to trigger the event?
I prefer that control classes are the only ones aware of the domain events.
What are pros and cons?
Upvotes: 0
Views: 142
Reputation: 97
In the case your controller starts doing event handling it will fail single responsability, so the best option in my opinion is to create an abstraction and let the client decide the algorith to inject in application service that will orchestrate your workflow (Use of strategy pattern, IOC, remove code smells, your code will start to be extensible and SOLID)
Hope this helps decide, Kind regards!
Upvotes: 1