title: Constructor-Injection when extending a class
body: <p>This question is not strictly related to Symfony 2, but as I use Symfony 2 components and will later likely use a Symfony\Component\DependencyInjection\Container as DI-Container, it might be relevant.</p>
  
  <p>I am currently building a small library using components from Symfony 2, e.g. HttpFoundation, Validator, Yaml. My Domain Services are all extending a basic AbstractService providing nothing but Doctrine\ORM\EntityManager and Symfony\Component\Validator\Validator via Constructor-Injection like this:</p>
  
  <pre><code>abstract class AbstractService
  {
      protected $em;
  
      protected $validator;
  
      /**
       * @param Doctrine\ORM\EntityManager $em
       * @param Symfony\Component\Validator\Validator $validator
       */
      public function __construct(EntityManager $em, Validator $validator)
      {
          $this-&gt;em = $em;
          $this-&gt;validator = $validator;
      }
  }
  </code></pre>
  
  <p>A Service-class extending this AbstractService may now need to inject additonal components, like Symfony\Component\HttpFoundation\Session. As of I do it like this:</p>
  
  <pre><code>class MyService extends AbstractService
  {
      /**
       * @var Symfony\Component\HttpFoundation\Session
       */
      protected $session;
  
      /**
       * @param Symfony\Component\HttpFoundation\Session $session
       * @param Doctrine\ORM\EntityManager $em
       * @param Symfony\Component\Validator\Validator $validator
       */
      public function __construct(Session $session, EntityManager $em, Validator $validator)
      {
          parent::__construct($em, $validator);
          $this-&gt;session = $session;
      }
  }
  </code></pre>
  
  <p>Is there a more elegant way to solve this without having to reiterate the parent's constructor arguments, e.g. by using Setter-Injection for Session instead?</p>
  
  <p>As I see it, when I use Setter-Injection for Session, I have to add checks before accessing it in my methods, whether it is already injected, which I want to avoid. On the other hand I don't want to "repeat" injecting the basic components shared by all services.</p>