Search code examples
design-patternsarchitectureentitydtodatacontract

Using DTO as Data Contract


I was just thinking instead of having a seperate set of assemblies for Data Contract for our service layer, why not use the DTO assembly as Data contract, making necessary changes in the Attributes like [Data contract] and [KnownType]. In other word what difficulties/ disadvantages we have when we use DTO as Data Contracts (offcourse with necessary modification of DTO). It will be helpfull if you can provide your view points on this. Thanks in advance.


Solution

  • I think exposing DTOs from your Service layer is a sensible use of DTOs.

    The drawbacks? You're adding complexity as you already have domain models.

    Using a mapping framework like AutoMapper or ValueInjector can reduce that problem.