views:

178

answers:

2

Or do you define a new object that contains the Root Entity object among others?

public class SomeAggregateName()
{
   public EntityRoot root {get;set;}
   public Entity entity {get;set;}
}

OR Is this the Aggregate implied?

public class EntityRoot()
{ 
   public Entity entity {get;set;}
}
+2  A: 

The aggregate is implied usually - ie, it is the Entity.

Your example makes it a little harder to follow because you haven't actually got a domain.

But let's take a classic example of an Order Aggregate Root, that contains OrderLines. The Order is an Entity - it is also the Aggregate Root. The OrderLine is contained within the Order Aggregate, so cannot be accessed directly outside of the Order Aggregate.

// This is the Order Aggregate Root
public class Order
{
    private IList<OrderLine> OrderLines { get; set; }
}
Michael Hart
A: 

A related question:

if I want to use FluentNHiberanate, for example, to initialize my domain entities it requires that my Order class look like this:

public class Order
{
    public virtual IList<OrderLine> OrderLines { get; set; }
}

this violates the encapsulation of the aggregate's internal entities. Any ideas on how to do it without breaking the encapsulation?


OK found it (one of the available solutions), change OrderLines member to private and add this to the mapping file:

HasMany(Reveal.Property<Order, IEnumerable<OrderLine>>("OrderLines"))
.Inverse()
.Cascade
.All();
Gai