All,
My typical approach for a medium sized WCF service would be something like:
- Define the interface using WCF data contracts and service operations. The data contracts would be POCO DTOs with no CRUD or domain logic.
- Model the domain using fully featured business objects.
- Provide some mechanism to go from DTO to BO and vice versa (see related question: http://stackoverflow.com/questions/3123167/pattern-strategy-for-creating-bos-from-dtos)
Now, a lot of the time (if not always) the data content of the business object and the DTO is near identical. How do people feel about creating a library of content objects which are shared by the BO and the DTO. E.g. if we had a WibbleDTO and a WibbleBO, we could create an IWibbleContent interface which both implement. We could even create an IWibbleContent interface and a WibbleContent class which both the DTO and BO hold a reference to.
So, specific questions:
- Do you ever share content/data interfaces between your DTOs and BOs?
- Do you ever share data content classes between your DTOs and BOs?
If not then I guess, as per my related question, we're left with tedious copying code, or we use something like AutoMapper.
Any comments appreciated.