title: Dependency injection not working with League\Route and League\Container
body: <p>I'm building a web application right now and I'm facing a problem with my controller.</p>
  
  <p>I want to send to my controller my League\Plate\Engine (registred in my Container) but I keep having the same error : <code>Argument 3 passed to App\Controller\Main::index() must be an instance of League\Plates\Engine, array given</code></p>
  
  <p>Here is my files :<br>
  <strong>dependencies.php</strong></p>
  
  <pre><code>use League\Container\Container;
  use Monolog\Handler\StreamHandler;
  use Monolog\Logger;
  use Yajra\Pdo\Oci8;
  use League\Container\ReflectionContainer;
  
  $container = new Container();
  
  // Active auto-wiring
  $container-&gt;delegate(
      new ReflectionContainer
  );
  
  // Others dependencies
  // ...
  
  // Views
  $container-&gt;add('view', function () {
      $templates = new League\Plates\Engine();
  
      $templates-&gt;addFolder('web', __DIR__ . '/templates/views/');
      $templates-&gt;addFolder('emails', __DIR__ . '/templates/emails/');
  
      // Extension
      //$templates-&gt;loadExtension(new League\Plates\Extension\Asset('/path/to/public'));
      //$templates-&gt;loadExtension(new League\Plates\Extension\URI($_SERVER['PATH_INFO']));
  
      return $templates;
  });
  
  return $container;
  </code></pre>
  
  <p><strong>routes.php</strong></p>
  
  <pre><code>use League\Route\RouteCollection;
  use Psr\Http\Message\ResponseInterface;
  use Psr\Http\Message\ServerRequestInterface;
  
  $route = new RouteCollection($container);
  
  // Page index
  $route-&gt;get('/', 'App\Controller\Main::index');
  
  // Others routes...
  
  return $route;
  </code></pre>
  
  <p><strong>Main.php</strong></p>
  
  <pre><code>namespace App\Controller;
  
  use Psr\Http\Message\ResponseInterface;
  use Psr\Http\Message\ServerRequestInterface;
  use League\Plates\Engine;
  
  class Main
  {
      public function index(ServerRequestInterface $request, ResponseInterface $response, Engine $templates) {
          //return $response-&gt;getBody()-&gt;write($this-&gt;templates-&gt;render('web::home'));
          return $response;
      }
  }
  </code></pre>
  
  <p>Thank you in advance</p>
  
  <hr>
  
  <p><strong>EDIT</strong><br>
  I've made a progress.
  I extended the Main class to extends the abstract class BaseController which looks like this :</p>
  
  <pre><code>namespace App\Controller;
  
  use League\Plates\Engine;
  
   class BaseController
  {
      protected $templates;
  
      public function __construct(Engine $templates) {
          $this-&gt;templates = $templates;
      }
  }
  </code></pre>
  
  <p>The first error goes away, but another one show up. In the Main class, I would like to use the <code>view</code> object that I instanciate in the container, but the object passed to the constructor is an empty one :</p>
  
  <p><strong>Main.php</strong></p>
  
  <pre><code>class Main extends BaseController
  {
      public function index(ServerRequestInterface $request, ResponseInterface $response) {
          echo '&lt;pre&gt;'.print_r($this-&gt;templates,1).'&lt;/pre&gt;'; // Return an empty Plate Engine object
          return $response-&gt;getBody()-&gt;write($this-&gt;templates-&gt;render('web::home'));
          //return $response;
      }
  }
  </code></pre>
  
  <p>And this doesn't explain why the first error shows up</p>
  
  <hr>
  
  <p><strong>EDIT 2</strong><br>
  After some digging, I finally make it works, but I sense that something is wrong.
  I replaced in the container the term <code>view</code> by the namespace of the Engine class :</p>
  
  <pre><code>$container-&gt;add('League\Plates\Engine', function () {
      // The same as before
  });
  </code></pre>
  
  <p>In <em>Main.php</em> I've updated the index function like this :</p>
  
  <pre><code>public function index(ServerRequestInterface $request, ResponseInterface $response) {
          $body = $response-&gt;getBody();
          $body-&gt;write($this-&gt;templates-&gt;render('web::home'));
          return $response-&gt;withBody($body);
      }
  </code></pre>
  
  <p>And the page doesn't throw a 500 error and the html file is displayed correctly.</p>
  
  <p>But, what if I want to change the template engine by <em>Twig</em> for example ? This would mean I'll need to change all the call to <code>$container-&gt;get('League\Plate\Engine');</code> by <code>$container-&gt;get('What\Ever');</code> ? That's not very practical!
  I probably missed something!
  And the problem will rise again when I'll want to use my PDO object... or every other object.</p>