Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazy Loading with a WCF Service Domain Model?

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?


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

like image 938
Toran Billups Avatar asked Aug 30 '08 01:08

Toran Billups


3 Answers

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.

like image 58
Ben Scheirman Avatar answered Oct 20 '22 04:10

Ben Scheirman


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!

like image 38
Jeremy McGee Avatar answered Oct 20 '22 05:10

Jeremy McGee


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

like image 40
noetic Avatar answered Oct 20 '22 03:10

noetic