I’ve see a few people recommend that a WCF service call the data layer, have an object containing data returned, and then putting that into a data contract. My question is why not stick the data contracts in the data layer itself and just return them instead? Is there a disadvantage to doing that? Reason I ask is that my data layer is just a class library and I want to be able to call it from multiple platforms that may not be using the webservice. I can’t seem to find a best practice regarding this. Any ideas?
Share
The disadvantage of putting your contracts in your datalayer is that you’re coupling your datalayer to your service contracts, when in fact they don’t need to be concerned with eachother. Ideally, your datalayer should be responsible for just doing what it says on the tin. What you might be looking for are Data Transfer Objects (DTO’s). They’re meant to just transfer data to your clients. In your servicelayer you can convert these back to their respective entities for doing whatever needs doing. This does create overhead however and you’ll need a way to map DTO’s and entities back and forth, for example with AutoMapper