I have a graph of objects more than two levels deep. It represents an entity with children and grandchildren (an aggregate):
A → B → C
I want to validate at all levels of the graph. I know I can access A when validating B using an overload of Must()
or using a Custom()
rule. I haven't figured out how to use these two techniques for accessing A from C's validator because there appears to be no context for that.
The only way I was able to do what I wanted was to create a new object that is a flattened representation. In other words create a wrapper that places A and C on the same level, which allows me to use the Must()
overload on C to get to A on the pseudo-parent Wrapper.
Wrapper → A → B → C
→ C
The problem is that I have to create yet another validator (for Wrapper in this case). I'd prefer to keep all my validation logic for a particular thing together.
Is there another way?