title: Symfony - Database connection with a Repository
body: <p>I'm refactoring the code in one of my Controller to put it in a service.</p>
  
  <p>In the Controller the entity manager is targeting a db connection called <strong>legacy</strong>. </p>
  
  <p>The problem is, I did not injected the Entity Manager in my service but just the OrderRepository.</p>
  
  <p>How can I target the good db connection with the repository in my service without the Entity Manager?</p>
  
  <p><strong>OrderController</strong></p>
  
  <pre><code>// In my Controller
  $em = $this-&gt;getDoctrine()-&gt;getManager('legacy');
  $em-&gt;persist($order);
  $em-&gt;flush();
  </code></pre>
  
  <p><strong>OrderService</strong></p>
  
  <pre><code>// In my Service
  public function __construct(OrderRepository $orderRepository)
  {
    $this-&gt;orderRepository = $orderRepository;
  }
  
  public function updateOrderStatus(Order $order)
  {
     // some code ...
  
     $this-&gt;orderRepository-&gt;save($order);
  }
  </code></pre>