Home  /  Questions  /  Question

108   96.7
Jun 11, 2012

Data Transfer Objects and Service Layer

Question about the Design Pattern Framework.

What is the purpose of the Data Transfer Objects in the Service Layer?
If I'm not using WCF is it possible to eliminate the DTOs in the Service Layer?
In the code we have:
var categories = _categoryDao.GetCategories();
response.Categories = Mapper.ToDataTransferObjects(categories);

If we did not use WCF we could we simply use:
return _categoryDao.GetCategories();


50   50
Jun 18, 2012

Data Transfer Object or DTO's are mainly used for sending information from one layer to another layer. It doesn't have any relation with WCF services.

Also, I have seen people uses DTO's in two ways:
  1. Keep common class for each layers and pass the information.
  2. Keep separate class for each layers and hide the information wherever you need.

Both approaches has its pros and cons. It totally depends on your choice what you need.

50   50
Jul 26, 2012

The Dto, for me at least, helps to enforce separation of concerns and in my view are used to

Passing Data between layers using serializable objects - helps with scaling if required later

Stopping business objects being passed from the service layer to the presentation layer

65   95.7
Aug 04, 2012
Hi, Dennis.

DTO's are for sending data across layers and is independent of WCF. They're great in cases where you need to add more data members, as your interface is not broken and, assuming you're employing versioning, can access the new members in your updated methods.