title: Injecting container to controller with league/route
body: <p>I'm using league/route and I want to inject my container to controller. Here's what I already have:</p>
  
  <p>Providing RouteCollection:</p>
  
  <pre><code>$this-&gt;getContainer()-&gt;share('route', function () {
      $route = require $this-&gt;getContainer()-&gt;get('baseDir').'/config/routes.php';
  
      return $route;
  });
  </code></pre>
  
  <p>baseDir/config/routes.php:</p>
  
  <pre><code>&lt;?php
  
  use League\Route\Strategy\ParamStrategy;
  use League\Container\ReflectionContainer;
  
  $routes = (new \League\Route\RouteCollection)
      -&gt;setStrategy((new ParamStrategy)-&gt;setContainer(new ReflectionContainer));
      // The line above is here because ParamStrategy otherwise throws
      // Uncaught exception 'RuntimeException' with message 'To use the parameter strategy,
      // the container must implement the (::call) method.
  
  $routes-&gt;get('/', 'Controller\PostController::index');
  
  return $routes;
  </code></pre>
  
  <p>My front controller:</p>
  
  <pre><code>/** @var RouteCollection $route */
  $route = $this-&gt;getContainer()-&gt;get('route');
  /** @var ServerRequest $request */
  $request = $this-&gt;getContainer()-&gt;get('request');
  /** @var Response $response */
  $response = $this-&gt;getContainer()-&gt;get('response');
  /** @var SapiEmitter $emitter */
  $emitter = $this-&gt;getContainer()-&gt;get('emitter');
  
  $response = $route-&gt;dispatch($request, $response);
  
  $emitter-&gt;emit($response);
  </code></pre>
  
  <p>And I have no idea where should I invoke the <code>setContainer</code> method on controller object because it lives only within <code>$route-&gt;dispatch($request, $response);</code>. What is the proper way to inject that container to my controller?</p>