What is the best way of using DTOs in a SOA application?

允我心安 提交于 2019-12-05 05:03:36

Forget all about the data layer. Create DTO:s that works for each specific web service call.

It's not important how the DTO is built or how it's used. The only thing that matters is how they are designed to minimize the amount of webservice calls for each operation.

For instance: Let's say that you have a use case where you need to traverse all users to to modify their addresses. A bad design would be if you first need to fetch all users and then make a webservice call for each user to fetch it's address. A proper design would be to return a list of UserWithAddress DTO:s in a single call.

then how we manage the huge amount of DTOs of a large project? you mean we should have a DTO for every single combination of UserInfo, such as UserWithAddress, UserWithAddressAndAge, UserWithAge,UserWithPhoneNumber,UserWithBlahBlahBlah? This would be a mess in large domains and hard to manage and maintain. I really prefer the Nullable DTOs. You should have a single Dto for each object mapped from the real world. this is the business duty to specify how it should be used. once you create a Dto, then use it according to you business. Calling GetUserAddress service, and don't expect UserAge or any other thing. there is a single DTO for Users as we map the user to our Object Oriented User in our design.

and one more thing! if we create a Dto for our each single purpose and combination of data services receives, as a developer who is joined to support team recently, how can i find a desired Dto for my new method? i should search all Dtos and be careful of my right choices (what happens if i be a lazy and careless developer?) maybe i should read a doc book like "THE DTOS OF THE PROJECT!" to become familiar with available DTOs.

DTOs should map to request or to capability based on need. You may aggregate various underlying data entities and return a composited or facade-like DTO, or you may return an anemic DTO that represents only a fraction of a single data entity. You want to balance payload, granularity and other SOA concerns when making this decision.

http://www.soapatterns.org/entity_abstraction.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!