php - symfony 5 - event not being dispatched

Solution:

Symfony will autowire your subscriber as service, if you will require it as argument in action:

public function commanderPanierAction(Request $request, SelectionWeb $selectionWeb, TableLumineuse $tableLumineuse, OrderSubscriber $orderSubscriber)

Of course, if your subscriber is registered properly.

But let me advice you not to create subscribers as objects manually. The main good thing about subscribers is that you know nothing about them, when you fire event. There could be dozens of subscribers to this event, and all of them will proceed your event. That will keep your code nice and lower cohesion.

It's in docs: https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-subscriber

Answer

Solution:

First I want to thank you all for your time and let me apologize my problem was due to a typo I wrote OrderSuscriber instead of OrderSubscriber that's why there was 2 services into my container and why defined service explicitly was working.

Source