title: PHP Dependency Injection - to inject Container (DIC) or not?
body: <p>Consider the following class structure:</p>
  
  <p><a href="https://i.stack.imgur.com/S256p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S256p.png" alt="enter image description here"></a></p>
  
  <p><strong><em>Framework code (blue zone)</em></strong></p>
  
  <ul>
  <li><strong>LOG class</strong> - simple logging class.</li>
  <li><strong>DATABASE class</strong> - gets LOG class injected. (for lets say, logging errors or SQL queries).</li>
  <li><strong>REDIS class</strong> - also gets LOG glass injected.</li>
  <li><strong>BUSINESS logic classes</strong> - gets all of those above constructor injected.</li>
  </ul>
  
  <p>.</p>
  
  <p><strong><em>Application code: (yellow zone):</em></strong></p>
  
  <ul>
  <li>Instantiate and use the framework code.</li>
  </ul>
  
  <p>Current framework constructor code is something like:</p>
  
  <pre><code>class Database{
      public function __constuctor (Logger $log, $databaseHost, $databaseUser, $databasePass, $databaseName){...}
  }
  class Redis{
      public function __constuctor (Logger $log, $redisHost, $redisUser, $redisPass){...}
  }
  class ACME{
      public function __constuctor (Database $db, Redis $redis, $otherStuff, ...){...}
  }
  </code></pre>
  
  <p>In the application we do something like:</p>
  
  <pre><code> $logger = new Logger();
   $db     = new Database($logger, 'db_host','db_user','db_user','db_pass');
   $redis  = new Redis($logger, 'redis_host','redis_user','redis_pass');
  
   $acme   = new Acme($db,$redis, ...other_stuf...);
  </code></pre>
  
  <p>The constructors gets pretty long and ugly and I am tempted to create a dependency container (DI) and to pass it as a single constructor parameter.
  .</p>
  
  <p>Consider the principle: "<em>The object should not be aware of the dependency container which contains it</em>", I feel that is not OK, because this will just replace the current multiple dependencies with a new one - the dependency container (DIC) itself.</p>
  
  <p>What I feel good is that I can use the injection of the DIC in the Application section (the yellow part of the image), but its NOT OK to inject the DIC in the base framework code (blue part).</p>
  
  <p>Am I wrong?</p>
  
  <p>Is it OK to inject the DIC?</p>
  
  <p>Isn't it better to use a service locator pattern here?</p>