title: Applying DDD principles with C# repositories
body: <p>I have a relatively simple domain model, as shown by the diagram. I would like to maintain this logic within my domain objects as defined by DDD.</p>
  <p>Each domain object is an abstract class which only contains its respective members and domain logic. Concrete implementations of these classes are returned by the repositories, supplied to the service (with DI).</p>
  <p>What I am having trouble with is understanding how to deal with the situation that I need to create a new entity. For example the domain logic dictates:</p>
  <p>An account can be added to a <code>Group</code> (creating a <code>Member</code> entity).</p>
  <ul>
  <li><p>When an account is added to a group, the new <code>Member</code> entity's <code>Value</code> property must be set to the total number of members that are already in the <code>Group</code>.</p>
  </li>
  <li><p>Every other member of the Group must have their value
  incremented by 1.</p>
  </li>
  </ul>
  <p>I could implement this as a <code>Member AddMember(Account account)</code> method on <code>Group</code>. However this method will somehow need to instantiate a new <code>Member</code> to add to the Group's Members collection.</p>
  <p>As the domain object's have no references to the layers further up in the application, and the domain objects themselves are abstract, I'm unsure how to go about constructing the new instance of Member.</p>
  <p>I have considered the possibility of defining an <code>abstract protected Member CreateMember()</code> method on the <code>Group</code> object that concrete implementations can implement but this seems messy to me and concerns me that I may be misunderstanding something more fundamental.</p>
  <p>While trying to stay true to DDD principles, how would I go about implementing this model?</p>
  <p><img src="https://i.stack.imgur.com/pRQbJ.png" alt="Domain Entity Diagram" /></p>