title: Injecting the "Container" in Symfony
body: <p>Since Symfony 5.1 injecting the Container by autowiring the <code>Psr\Container\ContainerInterface</code> is deprecated see <a href="https://symfony.com/doc/current/service_container.html#public-versus-private-services" rel="nofollow noreferrer">https://symfony.com/doc/current/service_container.html#public-versus-private-services</a></p>
  <p>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?</p>
  <p>One option would be to use <a href="https://symfony.com/blog/new-in-symfony-4-2-autowiring-by-type-and-name" rel="nofollow noreferrer">Autowiring by Name</a> and inject it, whenever there's a variable called <code>$container</code>, however that feels like a hack.</p>
  <p><strong>Question:</strong> What is the best practice of giving a service access to the container, if it still depends on it in Symfony 5.1+?</p>