BuildUp with nested objects

Oct 28, 2010 at 7:22 PM

Hi, I may not be firing on all cylinders today, but I'm having trouble visualizing the best way to do this. Given the following code:

public class Parent
{
    [Dependency]
    public ILogger Logger { get; set; }

    public string Name { get; set; }

    public Child Child1 { get; set; }
}

public class Child
{
    [Dependency]
    public ILogger Logger { get; set; }

    public string Name { get; set; }
}

And the following XML:
<Parent Name="John">
    <Child Name="Jane" />
</Parent>

Note: In my real code the hierarchy of objects is much deeper than 2 levels.

I deserialize the XML using the XmlSerializer, so I need to use setter injection.  Once the objects have been serialized, I call the BuildUp method on the top-level (Parent) object.  When I call BuildUp, my child objects (Child1 in this case) do not get built up, which is understandable.  My question is, what is the best way to get child objects to be built up?  Would I just walk the tree of objects and call BuildUp on each object and any properties it contains that need to be built up?  Would I create a BuilderStrategy to do this (an example would be nice if this is the way to go)?  Something else?