title: Slim Framework 3 - How to inject $logger to route controller
body: <p>I am using Slim Framework 3. I want to inject <code>$logger</code> defined in <code>dependencies.php</code> into a Router Controller class. Below is what I do, is there a better way?</p>
  
  <p><strong>routes.php</strong></p>
  
  <pre><code>$app-&gt;get('/test', function($request, $response, $args){
    $controller = new AccountController($this-&gt;get('logger'));
    return $controller-&gt;test($request, $response, $args);
  });
  </code></pre>
  
  <p><code>AccountController</code></p>
  
  <pre><code>class AccountController{
  
      private $logger;
      function __construct($logger){
          $this-&gt;logger = $logger;
      }
  
      public function test($request, $response, $args){
          $this-&gt;logger-&gt;info('i am inside controller');
          return $response-&gt;withHeader('Content-Type', 'application/json')-&gt;write('test');
      }
  }
  </code></pre>
  
  <p>In Slim Framework 3 documentation, the proper way of using a Route Controller should be:</p>
  
  <pre><code>$app-&gt;get('/test', 'AccountController:test');
  </code></pre>
  
  <p>But how do I inject <code>$logger</code> into AccountController when I choose to code my Route Controller in this more "elegant" way?</p>