title: How to inject specific Doctrine Entity Manager in Symfony2?
body: <p>Working on several projects which use the same database, we made a Symfony2 Bundle to map all common functions.</p>
  
  <p>Now the issue is that we have a second database, and we need the same kind of service, just as the first one.</p>
  
  <p><kbd><strong>config.yml</strong></kbd></p>
  
  <pre><code>doctrine:
    dbal:
      default_connection: main
      connections:
        main:
          /* ... */
        sub:
          /* ... */
  
    orm:
        default_entity_manager:   main
        entity_managers:
            main:
                connection:       main
                mappings:
                    AcmeMainBundle: ~
            sub:
                connection:       sub
                mappings:
                    AcmeSubBundle: ~
        auto_generate_proxy_classes: %kernel.debug%
  </code></pre>
  
  <p><kbd><strong>@AcmeMainBundle > services.yml</strong></kbd></p>
  
  <pre><code>services:
      mainmanager:
        class: Acme\MainBundle\MainManager
        arguments: [ @doctrine.orm.entity_manager ]
  </code></pre>
  
  <p><kbd><strong>Acme\MainBundle\MainManager</strong></kbd></p>
  
  <pre><code>class MainManager
  {
      public function __construct(EntityManager $em)
      {
          $em-&gt;getRepository('AcmeMainBundle:Foo');
      }
  }
  </code></pre>
  
  <p>This set works fine, I get all expected results since <code>default_entity_manager</code> is set to <code>main</code> which is the right EntityManager.  </p>
  
  <p>But now here's the issue.</p>
  
  <p><kbd><strong>@AcmeSubBundle > services.yml</strong></kbd></p>
  
  <pre><code>submanager:
    class: Acme\SubBundle\SubManager
    arguments: [ @doctrine.orm.entity_manager ]
  </code></pre>
  
  <p><kbd><strong>Acme\SubBundle\SubManager</strong></kbd></p>
  
  <pre><code>class SubManager
  {
      public function __construct(EntityManager $em)
      {
          $em-&gt;getRepository('AcmeSubBundle:Bar'); // Throws exception
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Unknown entity namespace alias AcmeSubBundle</p>
  </blockquote>
  
  <p>Since <code>EntityManager</code> goes into <code>main</code> by default.</p>
  
  <p>My question is, is there a <em>"clean"</em> way to inject a specific entity manager as argument in <strong>services.yml</strong> ?</p>