title: Symfony 2.0 getting service inside entity
body: <p>Im seraching over and cannot find answer. 
  I have database role model in my application. User can have a role but this role must be stored into database.</p>
  
  <p>But then user needs to have default role added from database. So i created a service:</p>
  
  <pre><code>&lt;?php
  
  namespace Alef\UserBundle\Service;
  
  use Alef\UserBundle\Entity\Role;
  
  /**
   * Description of RoleService
   *
   * @author oracle
   */
  class RoleService {
  
      const ENTITY_NAME = 'AlefUserBundle:Role';
  
      private $em;
  
      public function __construct(EntityManager $em)
      {
          $this-&gt;em = $em;
      }
  
      public function findAll()
      {
          return $this-&gt;em-&gt;getRepository(self::ENTITY_NAME)-&gt;findAll();
      }
  
      public function create(User $user)
      {
          // possibly validation here
  
          $this-&gt;em-&gt;persist($user);
          $this-&gt;em-&gt;flush($user);
      }
  
      public function addRole($name, $role) {
          if (($newrole = findRoleByRole($role)) != null)
              return $newrole;
          if (($newrole = findRoleByName($name)) != null)
              return $newrole;
  
          //there is no existing role
          $newrole = new Role();
          $newrole-&gt;setName($name);
          $newrole-&gt;setRole($role);
  
          $em-&gt;persist($newrole);
          $em-&gt;flush();
  
          return $newrole;
      }
  
      public function getRoleByName($name) {
          return $this-&gt;em-&gt;getRepository(self::ENTITY_NAME)-&gt;findBy(array('name' =&gt; $name));
      }
  
      public function getRoleByRole($role) {
          return $this-&gt;em-&gt;getRepository(self::ENTITY_NAME)-&gt;findBy(array('role' =&gt; $role));
      }
  
  }
  </code></pre>
  
  <p>my <code>services.yml</code> is:</p>
  
  <pre><code>alef.role_service:
      class: Alef\UserBundle\Service\RoleService
      arguments: [%doctrine.orm.entity_manager%]
  </code></pre>
  
  <p>And now I want to use it in two places:
  <code>UserController</code> and <code>User</code> entity. How can i get them inside entity?
  As for controller i think i just need to:</p>
  
  <pre><code>$this-&gt;get('alef.role_service');
  </code></pre>
  
  <p>But how to get service inside entity?</p>