Injecting dependency into entity repository

后端 未结 6 1488
有刺的猬
有刺的猬 2020-12-13 04:46

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

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 05:03

    You can actually create your own DefaultRepository extends EntityRepository, construct it with all dependencies you need and then set it as a default Repository with:

    doctrine:
        orm:
            entity_managers:
                default:
                    default_repository_class: AppBundle\ORM\DefaultRepository
    

提交回复
热议问题