Note that there are some explanatory texts on larger screens.

plurals
  1. POApplying DDD principles with C# repositories
    primarykey
    data
    text
    <p>I have a relatively simple domain model, as show by the attached diagram and simple domain logic. I would like to maintain this logic within my domain objects as defined by DDD.</p> <p>Each domain object is defined as an abstract class which only contains its respective members and domain logic. Concrete implementations of these classes are be 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 them self's 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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload