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.

Hi Snkar,

By Builder do you mean Constructor? Are you looking for the objects recieved from the webservice to go to the webservice and get there children on creation instead of what ever is calling the web service retreieving each of them and adding them to there parents?

I guess I was actually looking for a Lazy Load scenario. For example, lets say I have a domain entity Class A. As per my domain entity design, Class A contains the Id of the child class B as a property along with an object of Class B as a property. The web service returns the Id of the child Class B when I do a get on the data for Class A. Now I want to be able to retrive the child Class B data by calling the web service with the Id data already stored when someone requests the Child Class B property on Object of Class A. I have put together a quick class diagram to illustrate the scenario.

The issue is resolving the circular reference between the entity model and the service layer. The service layer method return types are the domain entities. Again, for lazy loading the entity object will need to have a reference to the service layer in order to invoke the web service.

Not sure of how to resolve this.

I would be very careful to do what you are suggesting. It will lead to an application that ignores the 7 fallacies of distributed computing.

If you want to do it though, build both the service layer and domain to be dependant on abstractions. Have the domain get an IFrameSet from the service layer and the service layer provide an IFrameSet, but it's own implementation.

See:
Fallacies of Distributed Computing
Dependency Inversion

I Finally ended up using Unity to resolve my dependencies. Thanks a lot for all the suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.