title: How to prevent 'newing' up instance all over the place in large codebase?
body: <p>I am working a really large code base with hundreds of different classes. We initially had a main <code>Application.php</code> where we kind of booted up our <code>services</code>. Meaning to say this is where we hooked dependencies into eachother similarly to something like this:</p>
  
  <pre><code>public function loadConfig(ConfigLocatorInterface $config) 
  {
      $this-&gt;config = new Config($config);
  }
  </code></pre>
  
  <p>Etc. You probably get the idea, there are multiple of these instances that might even take 2 or more dependencies or objects that already have dependencies.</p>
  
  <p>Along the way this gets unusable because you constantly have to pass these <code>serviceproviders</code> around to other objects, to your controller, to your connectionpool, etc.</p>
  
  <p>This is the reason my fellow developers started instantiating objects in the classes themselves instead of passing them along the chain, creating tight-coupling. Even <code>newing</code> up objects inside constructors, making it virtually impossible to <code>unit test</code> these pieces of code.</p>
  
  <p>Passing these dependencies along constantly might not be the solution in this case since a lot of constructors already have 3 or so arguments. And if we were to do this we would have to create chunks of pre-configured objects which is not always possible.</p>
  
  <p>A container seemed like a possibly solution but this is something that was voted against because of the concern of secure configuration data leaking out from the container and showing up in a callstack or somewhere else. Besides that my fellow developers are concerned this might turn in a bloated <code>'god-object'</code> where we pretty much dump everything we need that we don't want to pass around constantly.</p>
  
  <p>I am at my wits end with this and even though this is not a straightforward technical question I am wondering how you guys deal with this personally. I hope this is a viable question otherwise I will find somewhere else to post this. I would love the thoughts of this community though.</p>