dimanche 24 juin 2018

Aggregate root referencing a collection of entities

Following up on my previous post, I re-designed my model to make it more DDD oriented. I was probably missing a level of abstraction and I was also misusing domain services.

In my invitation system admins can only invite:

  • users that are not already invited
  • users that are not already in the system (=already a member)

This flow involves two entities Invitation and User.

In the new design, I want to implement two new aggregates:

InvitationDirectory which contain a list of invitations made by a specific "client" (should be a collection of 0-10 items max).

Adding or deleting an invitation would be made through this aggregate.

ProfileDirectory will list all profiles associated to an email address.

The code should look like this:

public class InvitiationList : IAggregateRoot
{
    private IList<Invitation> _invitations;

    public void Add(Invitation invitation, ProfileDirectory directory, User creator)
    {
        // Check + business logic + could also create the invitation here
        _invitations.Add(invitation); 
    }

    public void Delete(InvitationId id)
    {
        _invitations.Remove(...)
    }
}

Currently my aggregate root is keeping a reference to a list of entities. Is this a good practice?

Thx

Aucun commentaire:

Enregistrer un commentaire