title: Symfony 3.3 DI. Access a service name (class name) inside service factory
body: <p>I want to register all Doctrine repositories as services</p>
  
  <p>I found this approach: <a href="https://stackoverflow.com/questions/38505002/how-to-configure-dependency-injection-for-repository-class-in-symfony-3">How to configure dependency injection for repository class in symfony 3</a></p>
  
  <p>But this way I have to register every single one repository manually.</p>
  
  <p>I'd like to create some <a href="https://symfony.com/doc/current/service_container/factories.html" rel="nofollow noreferrer">Service Factory</a> that would instantiate repositories for me given just a repository class name.</p>
  
  <p>Something like this:</p>
  
  <p>
  
  <pre><code>namespace AppBundle\Service;
  
  use Doctrine\ORM\EntityManagerInterface;
  
  class RepositoryFactory
  {
      /**
       * @var EntityManagerInterface
       */
      private $manager;
  
      public function __construct(EntityManagerInterface $manager)
      {
          $this-&gt;manager = $manager;
      }
  
      public function getRepository(string $repositoryClass)
      {
          // do some magic that somehow obtaining actual repo
          return $repo;
      }
  }
  </code></pre>
  
  <p>service.yml</p>
  
  <pre><code>AppBundle\Service\RepositoryFactory:
    autowire: true
  </code></pre>
  
  <p>but Symfony's docs say nothing about how to pass service name that you want to instantiate (if it's even possible) in this factory </p>