Has anyone developed a mechanism for cascading validation from an aggregate root? In other words calling ValidateEntity on an object and having that intelligently call ValidateEntity on associated entities.
I'm trying to work out a design for this...possibly something like (off the top of my head...)
[AggregateValidationRoot]
public class RootEntity
{
[AggregateValidationNode]
public IEntity2 AssociatedEntity{get;set;}
public IEntity2 OptionalEntity{get;set;}
}
Then in the validator classes pull off some reflection to call validate on the nested objects...
....I'm not sure if declaritive is the way to go...I just don't want to write something like this...
bool IsValid
{
get{
return this.IsValid
&& this.AssociatedEntity != null
&& this.AssociateEntity.IsValid
&& this.AssociatedEntity.AnotherAssociatedEntity != null
&& this.AssociatedEntity.AnotherAssociatedEntity.IsValid
&& etc, etc...
}
}
This gets pretty nasty with a large object graph...