title: How do you access a users session from a service in Symfony2?
body: <p>Does anyone know how to access the session variable in a service?</p>
  
  <p>I have a service setup that I pass the container over to. I can access things like the Doctrine service by using:</p>
  
  <pre><code>// Get the doctrine service
  $doctrine_service = $this-&gt;container-&gt;get('doctrine');  
  // Get the entity manager
  $em = $doctrine_service-&gt;getEntityManager();
  </code></pre>
  
  <p>However, I'm not sure how to access the session.</p>
  
  <p>In a controller the session can be accessed using:</p>
  
  <pre><code>$session = $this-&gt;getRequest()-&gt;getSession();
  $session-&gt;set('foo', 'bar');
  $foo = $session-&gt;get('foo');
  </code></pre>
  
  <p>Is the session part of a service and if so what is the service called.</p>
  
  <p>Any help would be really appreciated.</p>