I have 3 services Service A, B, C which put and get data to/from Service D

|   Service A  |   Service B  |   Service C  |
|       |              |              |      |
|                  Service D                 |

Currently all 3 services A, B and C have exactly the same DTO's

So I have the same DTO in 3 different packages. Here example of the class

pulbic class TemplateDto {

    private Long    id;

    private String  name;

    private Integer someNumber


here the packages where the above DTO is contained:


I thought it's best to keep different DTO's for the future in case they change

In service D should I implement 3 different puts and gets for all the different DTO's or is there a better way without having to produce so much duplicated code?

  • Do the DTO classes refer to data that is owned by services A,B or C, or is the data owned by service D? Commented Feb 22, 2019 at 10:35
  • @BartvanIngenSchenau they refer to data owned by service D. But I thought the DTO's should differ because maybe service A needs one more field in the future that the others don't etc.
    – Alex P.
    Commented Feb 22, 2019 at 10:38

1 Answer 1


What I understand is you are added as Service Reference of these services and those DTO coming as Proxy classes.

Whether it is true or not, do not create any D Service method depends on A, B or C services' DTO. Create your own model and use it in your D service method. Just write mapper for DTO to new model. It will better solution to ignore duplicated methods.

If you also don't want to engage with same DTO coming from different service namespaces, you can create seperate dll library which contains DTO and use it all A, B, C and D service and cast the DTO by using third party dll like Newtonsoft.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.