title: Symfony2 injecting entityManager error
body: <p>I am following a Doctrine ORM Symfony2 <a href="http://symfony.com/doc/current/book/doctrine.html#book-doctrine-field-types" rel="nofollow">Documentation</a>. When it comes to Persisting Objects to the Database I get this error:</p>
  
  <pre><code>Attempted to call an undefined method named "getDoctrine" of class "BooksApi\BookBundle\Controller\IndexController".
  </code></pre>
  
  <p>The only thing I am doing differently in my code is that I am trying to create EntityManager as a service....</p>
  
  <p>services.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;container xmlns="http://symfony.com/schema/dic/services"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"&gt;
      &lt;services&gt;
          &lt;service id="booksapi.controller.index"
                   class="BooksApi\BookBundle\Controller\IndexController"&gt;
              &lt;argument type="service" id="booksapi.repositories.test_repository" /&gt;
              &lt;argument type="service" id="doctrine.orm.entity_manager" /&gt;
          &lt;/service&gt;
      &lt;/services&gt;
  &lt;/container&gt; 
  </code></pre>
  
  <p>my Index Controller:</p>
  
  <pre><code>&lt;?php
  
  namespace BooksApi\BookBundle\Controller;
  
  use BooksApi\BookBundle\Entity\BooksEntity;
  use Doctrine\ORM\EntityManager;
  use Symfony\Component\HttpFoundation\Response;
  
  
  class IndexController
  {
      /**
       * @var EntityManager
       */
      public $em;
  
      /**
       *  @param EntityManager $entityManager
       */
      public function __construct(
          EntityManager $entityManager
      ){
          $this-&gt;em = $entityManager;
      }
  
      /**
       * @return Response
       */
      public function testAction()
      {
  
          $book = new BooksEntity();
          $book-&gt;setTitle('Tomazi in da Jungle');
          $book-&gt;setPrice('19.99');
          $book-&gt;setDescription('Lorem ipsum dolor');
  
          $this-&gt;em = $this-&gt;getDoctrine()-&gt;getManager();
  
          $this-&gt;em-&gt;persist($book);
          $this-&gt;em-&gt;flush();
  
          return new Response('Created product id '.$book-&gt;getId());
      }
  }
  </code></pre>
  
  <p>So looking at the error getDoctrine method is not recognised....any idea why...?
  How can I fix this.</p>