Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate initialisation of repositories #220

Merged

Conversation

Fantus
Copy link

@Fantus Fantus commented Nov 22, 2020

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #217
License MIT

Accessing a repository via EntityManger::getReposiory and direct injection via the dot notation of the repository will yield different instances of the same repository. This is caused by:

  • Repositories are not injected into the ServiceLocator of ContainerRepositoryFactory as the required tag doctrine.repository_service is missing for our generated the repositories
  • Even when injected (after adding that doctrine.repository_service) the ContainerRepositoryFactory::getRepository method cant resolve the repository as its injected with the dot notation and doctrine looks for the repository by class name
  • Problem also exists for default repositories but simply tagging them does not work

Solution/Changes;
For the solid repositories:

  • Tag the solid repositories so they get injected
  • Switch to service id to class name
  • Create a public alias to maintain old functionality

For generic default repositories (cant be tagged as all use the same class)

  • Init default repositories via doctrine factory so its using ContainerRepositoryFactory and by that prevent duplicate initialisation
  • Decorated ContainerRepositoryFactory to be table to return the sylius EntityRepository instead of the default doctrine one

@Fantus Fantus requested a review from a team as a code owner November 22, 2020 13:06
@Fantus Fantus changed the title Preventing the duplicate initialisation of repositories when access v… Duplicate initialisation of repositories Nov 22, 2020
@Fantus Fantus force-pushed the #217_duplicate_initialisation_of_repositories_v2 branch from 3458bfe to c573e6b Compare November 22, 2020 13:08
…ia entity manager and dependency injection

Fixes: Sylius#217
@Fantus Fantus force-pushed the #217_duplicate_initialisation_of_repositories_v2 branch from c573e6b to 2baf357 Compare November 22, 2020 13:09
…ia entity manager and dependency injection

Fixes: Sylius#217
@Fantus Fantus force-pushed the #217_duplicate_initialisation_of_repositories_v2 branch from 426aada to 117fb44 Compare November 22, 2020 13:29
@Fantus Fantus force-pushed the #217_duplicate_initialisation_of_repositories_v2 branch from 66ca1ac to 3ceb1ba Compare November 23, 2020 13:34
@pamil pamil merged commit 45494f6 into Sylius:master Nov 23, 2020
@pamil
Copy link
Contributor

pamil commented Nov 23, 2020

Thank you, Justus! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate initialisation of repositories
2 participants