Feels like a bit of a stupid question considering it’s perhaps the simplest part of a domain model/ddd approach and given the amount of reading I’ve done on entity equality/identity, repository implementations, nhibernate, session/uow, IoC and all the other fads/techs/patterns. Think I might just be confusing myself here but we’ll see.
How do I handle the relationship/references in the following domain model? A theme park has one or more sectors within it and each sector has one or more attractions, the attractions therefore belong to both the location and the theme park (e.g. ‘Splash Mountain’ is a ride at ‘Magic Kingdom’ within the ‘Frontierland’ sector of the park). How do I model that correctly?
class ThemePark : Entity
{
...
public virtual IEnumerable<Sector> Sectors { get; protected set; }
...
}
class Sector : Entity
{
...
public virtual ThemePark Park { get; set; }
public virtual IEnumerable<Attraction> Attractions { get; protected set; }
...
}
For the attraction do I reference the park and sector it belongs to or just the sector? Do I maintain a list of the attractions from within the Park object? Do I even need those ‘up’ references to the parent objects? Obviously I’d be using an IParkRepository implementation but that means if I just want to list all attractions, at say all Disney parks, I have to cascade through the ParkRepository selecting all the parks, all their sectors and then all the attractions belonging to each sector. Do I use a seperate IAttractionRepository? The actual parks are the root of the aggregate though so another repository contradicts my understanding of DDD. Should I go read again or am I just over complicating things and having a doh moment?