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
This is a YAML version of Aldo's answer, just in case you are using YAML configurations instead of XML
your_namespace.repository.repos_name:
class: %your_namespace.repository.repos_name%
factory: ["@doctrine", getRepository]
arguments:
- entity_name
- entity_manager_name
calls:
- [setContainer, ["@service_container"]]
And prior to version 2.8:
your_namespace.repository.repos_name:
class: %your_namespace.repository.repos_name%
factory_service: doctrine
factory_method: getRepository
arguments:
- entity_name
- entity_manager_name
calls:
- [setContainer, [@service_container]]
Also, as a note, entity_manager_name is an optional parameter. I want the default for my particular use, so I just left it blank (just in case I ever rename the default manager).