Note : This article is the translate of this article. I use Google Translate for help me to write in english. Please, if you read wrong phrase send me the correct by one comment.

In a refactoring sprint, I found that my main aggregate class took much overweight.

I had exceeded 750 lines of code with, in many actions, a « switch » or a dozen « IF ». This did not please me very much because, if a change was required with this level, the amendment would be difficult.

For use the default event bus, you must tag any services with broadway.domain.event_listener and extend this class Broadway\Processor\Processor.
All services will be injected into the event bus by a compiler pass. The latter takes 3 arguments: the event bus service identifier, the tag used for get all services to inject her, and the interface name that services must implement to be injected.

You can reuse the code to add a new event bus without write more code.

3 steps for separate into new bus all services necessary for refresh view.

1) Add a new event bus

YAML

1

2

3

4

5

# src/Vendor/Bundle/NameBundle/Ressources/config/services.yml

service:

mon_bundle.event_handling.event_bus:

class: Broadway\EventHandling\SimpleEventBus

lazy: true

2) Add new tag for all services to update the view. By exemple mon_bundle.domain.event_listener.
3) Run new compiler pass with new parameters

Finally, during the retransmission of events, simply send them on the bus dedicated to replay events to perform the update only the view.
That’s done! You can retransmit all the events to update the view without having to change the configuration of the production application to prevent the resend of the emails.

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.