Injecting the "Container" in Symfony

Since Symfony 5.1 injecting the Container by autowiring the PsrContainerContainerInterface is deprecated see

In case a service still needs access to the Container, does it needs to be injected by hand for the future, or is there another, more convenient, way to inject it?

One option would be to use Autowiring by Name and inject it, whenever there’s a variable called $container, however that feels like a hack.

Question: What is the best practice of giving a service access to the container, if it still depends on it in Symfony 5.1+?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *