I have noticed three different ways to get an entity repository from within a Shopware 6 controller or service.
- Inject the repo as a container parameter, e.g.
<argument type="service" id="product.repository"/>
- Retrieve it from the DefinitionInstanceRegistry, e.g.
$productRepository = $this->definitionInstanceRegistry->getRepository(ProductDefinition::ENTITY_NAME);
- Get it from the container directly e.g.
$productRepository = $this->container->get('product.repository');
As it appears to me all three methods produce the same result. What are the differences, if any, and what is the recommended approach to use?