title: ZF2: Dependency injection done the proper way
body: <p>I am new to ZendFramework 2 and the whole DI idea.</p>
  
  <p>Here is what I need to achieve:</p>
  
  <ol>
  <li>Create many Model classes extending a single AbstractModel</li>
  <li>Supply that AbstractModel using DI with dependencies (in my case the doctrine entity manager)</li>
  <li>Use the ancestor classes wherever I need them as normal classes</li>
  </ol>
  
  <p>To better explain 3. lets see this example:</p>
  
  <pre><code>class Ancestor extends Parent { }
  </code></pre>
  
  <p>In a controller, or ideally anywhere:</p>
  
  <pre><code>$ancestor = new Ancestor();
  $ancestor-&gt;doStuffWithEntityManager();
  </code></pre>
  
  <p>Uppon initializing ancestor it must already be aware of the injected resources.</p>
  
  <p>Is this even possible? If not use in it's default form I am ok with initializing the ancestor via some service managers etc. as long as I don't need to specify each and every ancestor. I need to tell zend: inject this and that into every class that extends/implements X.</p>
  
  <p>Any ideas?</p>
  
  <p>P.S.: As I said I am quite new, so please specify the configuration/class file I must add each piece of example code.</p>