title: Inject service in symfony2 Controller
body: <p>How can I inject a service (the service that I created) into my Controller? 
  A setter injection would do.</p>
  
  <pre><code>&lt;?php
  namespace MyNamespace;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  
  class MyController extends Controller
  {
      public function setMyService(MyService $myService)
      {
          $this-&gt;myService = $myService;
      }
  
      public function indexAction()
      {
          //Here I cannot access $this-&gt;myService;
          //Because the setter is not called magically!
      }
  }
  </code></pre>
  
  <p>And my route settings : </p>
  
  <pre><code>// Resources/routing.yml
  myController_index:
      pattern:  /test
      defaults: { _controller: "FooBarBundle:MyController:index" }
  </code></pre>
  
  <p>I'm setting the service in another bundle :</p>
  
  <pre><code>// Resources/services.yml 
  parameters:
     my.service.class: Path\To\My\Service
  
  services:
      my_service:
          class: %my.service.class%
  </code></pre>
  
  <p>When the route is resolved, the service is not injected ( I know it shouldn't ).
  I suppose somewhere in a yml file, I have to set: </p>
  
  <pre><code>    calls:
          - [setMyService, [@my_service]]
  </code></pre>
  
  <p>I am not using this Controller as a service, it's a regular Controller that serves a Request.</p>
  
  <p>Edit: At this point in time, I am getting the service with $this->container->get('my_service'); But I need to inject it.</p>