mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Question: Why is Doctrine\ORM\EntityRepository#getEntityManager() protected? #5635
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @spackmat on GitHub (Aug 11, 2017).
Originally assigned to: @Ocramius on GitHub.
Hi,
I am refactoring my Symfony controllers to get the EntityRepositories injected instead of the whole EntityManager. This works fine, but in some cases (transactions, changing listeners etc.), I still need access to the EntityManager.
But the Doctrine\ORM\EntityRepository#getEntityManager() method is protected. This surely is intentional, so my question is: Would it be bad practice to access the EntityManager through (injected) repositories? Or are there other reasons for the protection?
Greets,
spackmat
@Ocramius commented on GitHub (Aug 11, 2017):
Yes, it is out of the responsibility of the
EntityRepositoryto provide its dependencies to you. The same applies to basically any service. The method should beprivate, but it was madeprotectedsince this class was initially designed for inheritance.You'd inject a separate
EntityManager.