views:

1358

answers:

4

I'm looking to push my domain model into a WCF Service API and wanted to get some thoughts on lazy loading techniques with this type of setup.

Any suggestions when taking this approach?

+2  A: 

As for any remoting architecture, you'll want to avoid loading a full object graph "down the wire" in an uncontrolled way (unless you have a trivially small number of objects).

The Wikipedia article has the standard techniques pretty much summarised (and in C#. too!). I've used both ghosts and value holders and they work pretty well.

To implement this kind of technique, make sure that you separate concerns strictly. On the server, your service contract implementation classes should be the only bits of the code that work with data contracts. On the client, the service access layer should be the only code that works with the proxies.

Layering like this lets you adjust the way that the service is implemented relatively independently of the UI layers calling the service and the business tier that's being called. It also gives you half a chance of unit testing!

Jeremy McGee
A: 

when I implemented this technique and step into my app, just before the server returns my list it hits the get of each property that is supposed to be lazy loaded ... Thus eager loading. Could you explain this issue or suggest a resolution?

Edit: It appears you can use the XMLIgnore attribute so it doesn’t get looked at during serialization .. still reading up on this though

Toran Billups
+3  A: 

Don't do lazy loading over a service interface. Define explicit DTO's and consume those as your data contracts in WCF.

You can use NHibernate (or other ORMs) to properly fetch the objects you need to construct the DTOs.

Ben Scheirman
I'm stuck in the world of ado.net only ... any chance you could provide a sample of this approach you mentioned?
Toran Billups
Basically you need to create a ProxyCollection, that inherits from IList or ICollection, and this needs to be able to keep track of the command to load the items. upon accessing any of the members, first execute the command to populate the list.
Ben Scheirman
+1  A: 

You could try to use something REST based (e.g. ADO.NET Data Services) and wrap it transpariently into your client code.

noetic