I got the same problem as you do today.
The problem is that fpn_tag.tag_manager
depends on doctrine.orm.default_entity_manager
, but the TagListener
is a dependency of doctrine.orm.default_entity_manager
if you tag it with doctrine.event_subscriber
. Thus creating a circular dependency. But this is not detected by the service container, instead it tries to add the events after the doctrine connection service is returned. See more details here.
There are two ways to fix this
- You can inject the service container into the
TagListener
, then loadfpn_tag.tag_manager
on demand. - Create a listener on
kernel.request
event, then manually add the event subscriber to the entity manager.
A side note, I'd recommend against calling saveTagging
inside preUpdate
and prePersist
events. Because saveTagging
does a implicit flush, which is not safe to call in these events.