DDD adding to a collection

Viewed 21

Consider the following scenario

I have an aggregate root of Fleet (as in a fleet of airplanes)

public class Fleet
{
    public string Name { get; set; }
    public Guid Id { get; set; }
    public IEnumerable<Aircraft> Aircraft { get; }
    public void AddAircraft(Aircraft aircraft)
    {
        
    }
}

public class Aircraft
{
    public string Name { get; set; }
    public Guid Id { get; set; }
    public string IcaoCode { get; set; }
    ...
}

There are many fleets, and an aircraft can only belong to one fleet

When adding an aircraft to a fleet I need to check if it already belongs to a fleet and if it does, then stop the add from completing

What is the best way to do this? Is it a candidate for a service? If so, what would you do with the Add method on the Fleet object, it doesn't feel that this should be there any more, but how do I then actually add to the Aircraft collection

0 Answers
Related