Is there a simple way to inject a dependency into every repository instance in Doctrine2 ?
I have tried listening to the loadClassMetadata event and usi
Problem is that repository classes are not part of the Symfony2 codebase as they are part of Doctrine2, so they do not take advantage of the DIC; this is why you can't go for injection in one place for all repositories.
I would advice you to use a different approach. For example you can create a service layer on top of the repositories and actually inject the class you want through a factory in that layer.
Otherwise you could also define repositories as services this way:
entity_name
entity_manager_name
your_argument
A solution that could centralize the set method call is to write a DIC tag and a compiler pass to handle it and tag all repository services.