title: DDD: is it ok to inject a Service into an Entity
body: <p>I have a tree of <code>Zone</code> objects:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>class Zone {
      protected $parent;
  
      public function __construct(Zone $parent) {
          $this-&gt;parent = $parent;
      }
  }
  </code></pre>
  
  <p>There are <strong>no</strong> <code>children</code> nor <code>descendants</code> property in the Zone, because I want to avoid the pain of managing these relationships in the domain model.</p>
  
  <p>Instead, a domain service maintains a closure table in the database, to map a zone to all its descendants, at any level.</p>
  
  <p>Now, I have a <code>User</code> which can be assigned one or more Zones:</p>
  
  <pre class="lang-php prettyprint-override"><code>class User {
      protected $zones;
  
      public function assignZone(Zone $zone) {
          $this-&gt;zones[] = $zone;
      }
  }
  </code></pre>
  
  <p>My problem is that, prior to assigning a new Zone to the User, I'd like to check that this Zone is not already assigned, either explicitly or implicitly via one of its descendants.</p>
  
  <p>Therefore I'd like my controller to transiently inject the Service into this method, to perform the necessary checks:</p>
  
  <pre class="lang-php prettyprint-override"><code>class User {
      protected $zones;
  
      public function assignZone(Zone $newZone, ZoneService $zoneService) {
          foreach ($this-&gt;zones as $zone) {
              if ($service-&gt;zoneHasDescendant($zone, $newZone)) {
                  throw new Exception('The user is already assigned this zone');
              }
          }
  
          $this-&gt;zones[] = $zone;
      }
  }
  </code></pre>
  
  <p>Is that a good practice, or if not, what's the correct alternative?</p>