title: how to register calss in php-di to automatically call some method when instantiated
body: <p>i run controller this way</p>
  
  <pre><code>$controller = $this-&gt;getContainer()-&gt;get($class);
  $controller-&gt;{$method}(...array_values($vars));
  </code></pre>
  
  <p>now inside controller i need to use models
  if i try to autowire model like </p>
  
  <pre><code>class MyClass extends Controller
  {
      public function doSmth(myModel $myModel)
      {
             $myModel-&gt;getAll());
      }
  }
  </code></pre>
  
  <p>i receive error about wrong parameter types.
  controller methods shouldnt always use some model and because of this models need to be instantiated inside methods .</p>
  
  <p>ok, then im trying to 
  instantiate model directly</p>
  
  <pre><code>class MyClass extends Controller
  {
      public function doSmth()
      {
             $myModel = new myModel();
             $myModel-&gt;getAll());
      }
  }
  </code></pre>
  
  <p>but i receive problem that i need instance of the container inside the model (to set up DB connection for example, and these settings registered inside container).
  i could transfer the container instance from the controller to the model like this:</p>
  
  <pre><code>class MyClass extends Controller
  {
      public function doSmth()
      {
             $myModel = new myModel($this-&gt;container);
             $myModel-&gt;getAll());
      }
  }
  </code></pre>
  
  <p>but i would have to do this every time i need some model and this is ugly ...</p>
  
  <p>im new to the php-di. i know that when im instantiating inside the method DI doesnt track it  ...
  just dont know how to set this altogether ?</p>