title: Domain Driven Design and IoC/Dependency Injection
body: <p>I'm trying to apply now what I learned about DDD and I'm a little bit confused about the flow of dependencies in the Domain model.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Should an Entity be aware of Factories, Repositories, Services in the domain?</li>
  <li>Should a Repository be aware of Services in the domain?</li>
  </ol>
  
  <p>Another thing that is bothering my mind is how to treat to collections when I want to add and entity to the collection.</p>
  
  <p>Let's say I'm developing a simple CMS. In the CMS I have an Article Entity and Tags collection which contains Tag Entities.</p>
  
  <p>Now, in case I want to add a relation with a new tag. What would be the better way to do it? (Example in PHP)</p>
  
  <pre><code>$article-&gt;tags-&gt;add(TagEntity);
  $articleRepository-&gt;save($article);
  </code></pre>
  
  <p>or I can do it with a service.</p>
  
  <pre><code>$articleService-&gt;addTag($article, TagEntity);
  </code></pre>
  
  <p>What do you think?</p>
  
  <p>Thanks.</p>