title: Symfony 3.3 - Entity Manager injection into services with multiple database?
body: <p>I have recently added a new database to my Symfony 3.3 application.
  Then my services with injected entity manager are no longer working and return the following error:</p>
  
  <blockquote>
    <p>Cannot autowire service "RouterBundle\Utils\RoutersUtils": argument
    "$em" of method "__construct()" references class
    "Doctrine\ORM\EntityManager" but no such service exists. Try changing
    the type-hint to one of its parents: interface
    "Doctrine\ORM\EntityManagerInterface", or interface
    "Doctrine\Common\Persistence\ObjectManager".</p>
  </blockquote>
  
  <p>So my config.yml file is now like :</p>
  
  <pre><code># Doctrine Configuration
  doctrine:
      dbal:
          default_connection: router
          connections:
              router:
                  driver: pdo_mysql
                  host: '%database_host%'
                  port: '%database_port%'
                  dbname: '%database_router_name%'
                  user: '%database_router_user%'
                  password: '%database_router_password%'
                  charset: utf8mb4
                  default_table_options:
                      charset: utf8mb4
                      collate: utf8mb4_unicode_ci
                      row_format: DYNAMIC
              app:
                  driver: pdo_mysql
                  host: '%database_host%'
                  port: '%database_port%'
                  dbname: '%database_app_name%'
                  user: '%database_app_user%'
                  password: '%database_app_password%'
                  charset: utf8mb4
                  default_table_options:
                      charset: utf8mb4
                      collate: utf8mb4_unicode_ci
  
      orm:
          default_entity_manager: router
          entity_managers:
              router:
                  connection: router
                  mappings:
                      RouterBundle:  ~
                  dql:
                      string_functions:
                          # Match agains should have the path to the Sha1 class created in the previous step
                          SHA1: RouterBundle\Extensions\Doctrine\Sha1
              app:
                  connection: app
                  mappings:
                      AppBundle: ~
  </code></pre>
  
  <p>One of my service like :</p>
  
  <pre><code>&lt;?php
  
  namespace RouterBundle\Utils;
  use Doctrine\ORM\EntityManager;
  
  class RoutersUtils
  {
  
      protected $em;
  
      public function __construct(EntityManager $em)
      {
          $this-&gt;em = $em;
      }
  
  ...
  </code></pre>
  
  <p>and my services.yml ( I tried to add this arguments but doesn't work)</p>
  
  <pre><code>...
  RouterBundle\Utils:
      public: true
      arguments:
          - '@doctrine.dbal.router_connection' 
  ...
  </code></pre>
  
  <p>Any idea how to inject the correct Entity Manager?
  Can I also inject entity manager by default using the "default_entity_manager: router" parameters in teh config file ?</p>
  
  <p>Thanks for the help !</p>
  
  <p>Pierre</p>