Build nested or hierarchical object graphs in C#

759 views Asked by At

I have an object hierarchy that can be represented simplistically like:

public class ChannelEntity
{
    ... public properties ....
    public FramesetEntity Frameset { get; set; }
}
public class FramesetEntity
{
    ... public properties ....
    public List<FrameEntity> Frames { get; set; }
}
public class FrameEntity
{
    ... public properties ....
    public List<TimeslotEntity> TimeSlots { get; set; }
}
public class TimeslotEntity
{
    ... public properties ....
    public PlaylistEntity Playlist { get; set; }
}

and so on with some objects containing multiple nested objects. Now I am trying to figure out a generic and elegant way to construct the full object hierarchy with the individual objects available. A s a background, I am getting the individual objects from a web service where the return object contains the identifier for the nested child using which I am subsequently again calling the service to get the nested object data. Once I have resolved all the necessary data, I was trying to figure out a way to create the complete object hierarchy using respective builders for the individual objects having the responsibility of creating itself and the necessary childs(through their builders) so that the caller can be isolated from having to create the entire object graph manualy.

0

There are 0 answers