Questions tagged [dto]

DTO is an acronym for Data Transfer Object, a design pattern used in data transfer.

DTO is an acronym for Data Transfer Object, a design pattern used in transferring data through internal or external interfaces. A DTO protects the application's internal data by acting as dummy storages, the whole logic is implemented only in actual Domain Objects (DO).

Pros:

  • Fewer remote calls (typically one, getDto() vs. individual getId(), getName(), etc.)
  • Improved data capsulation (Remote systems need only to know the details of the DTO, not DO internals)

Cons:

  • class explosion
  • conversions needed between DTOs and DOs
2100 questions
25
votes
4 answers

How to use DTOs in the Controller, Service and Repository pattern

I'm following the Controller, Service and Repository pattern and I'm just wondering where DTOs come into this. Should the controller only receive DTOs? My understanding is you wouldn't want the outside world to know about the underlying domain…
kcon123
  • 460
  • 2
  • 5
  • 13
25
votes
2 answers

Should service layer accept a DTO or a custom request object from the controller?

As the title suggests what is the best practice when designing service layers?. I do understand service layer should always return a DTO so that domain (entity) objects are preserved within the service layer. But what should be the input for the…
Vino
  • 2,111
  • 4
  • 22
  • 42
24
votes
3 answers

What format (MIME Type) should I use for HTML5 drag and drop operations?

I'm starting to experiment with HTML5 Drag and Drop. Then, in the dragstart event handler we should run setData(), which receives two parameters: format and data. function dragstart_handler(ev) { ev.dataTransfer.setData('text/plain',…
Denilson Sá Maia
  • 47,466
  • 33
  • 109
  • 111
24
votes
1 answer

DTO shape: flat, complex/nested, or a mixture of both

I have an MVC2 n-tier application (DAL, Domain, Service, MVC web) using a DDD approach (Domain Driven Design), having a Domain Model with repositories. My service layer uses a Request/Response pattern, in which the Request and Response objects…
tbehunin
  • 1,043
  • 1
  • 12
  • 24
24
votes
2 answers

ApiController vs ODataController when exposing DTOs

Can someone explain me when I should inherit my controller form ODataController vs ApiController ? The question is caused by the fact that results returned by ApiController can be filtered with OData query. If I apply QueryableAttribute to…
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
23
votes
2 answers

JPA Entities and/vs DTOs

What is the general idea to help deciding when to use DTO and when to use Entity in these cases ? UI / server side java calling the services. Should it get / send entities or DTOs ? Web service calling the services. Should the services accept…
Bertie
  • 17,277
  • 45
  • 129
  • 182
23
votes
6 answers

Unit testing of DTOs

Is it appropriate and necessary to test getters and setters? I think they haven't any logic and they can't crash or throw any exceptions.
Shikarn-O
  • 3,337
  • 7
  • 26
  • 27
23
votes
4 answers

Json A circular reference was detected while serializing an object of type

Give the classes: public class Parent { public int id {get; set;} public int name {get; set;} public virtual ICollection children {get; set;} } [Table("Child")] public partial class Child { [Key] public int id {get;…
Expert wanna be
  • 10,218
  • 26
  • 105
  • 158
23
votes
4 answers

prefixing DTO / POCOS - naming conventions?

simple question really, i was wanting to know what naming conventions anybody puts on there DTO / POCOS .... I didn't really want to prefix like hungarian notation.. i got away from that!. But my dtos naming are clashing with my actual returned…
mark smith
  • 20,637
  • 47
  • 135
  • 187
22
votes
3 answers

POCO's, DTO's, DLL's and Anaemic Domain Models

I was looking at the differences between POCO and DTO (It appears that POCO's are dto's with behaviour (methods?))and came across this article by Martin Fowler on the anaemic domain model. Through lack of understanding, I think I have created one…
dan
  • 5,664
  • 8
  • 45
  • 59
22
votes
8 answers

Entity Framework + AutoMapper ( Entity to DTO and DTO to Entity )

I've got some problems using EF with AutoMapper. =/ for example : I've got 2 related entities ( Customers and Orders ) and they're DTO classes : class CustomerDTO { public string CustomerID {get;set;} public string CustomerName {get;set;} …
shkipper
  • 1,403
  • 3
  • 21
  • 35
22
votes
6 answers

Should I map a DTO to/from a domain entity on both client and server sides?

I've got a rich domain model, where most classes have some behaviour and some properties that are either calculated or expose the properties of member objects (which is to say that the values of these properties are never persisted). My client…
Jay
  • 56,361
  • 10
  • 99
  • 123
22
votes
3 answers

Alternative to dozer for bean mapping?

I am trying to figure out an easy way to map DTOs to entities without the boiler-plate code. While I was thinking of using dozer it appears to require a lot of xml configuration. Has anybody seen a dozer alternative that uses a DSL to configure…
benstpierre
  • 32,833
  • 51
  • 177
  • 288
21
votes
10 answers

@MAPSTRUCT. No property named "packaging" exists in source parameter(s)

I am writing an MVC REST application with Spring Boot and Hibernate. I decided to do DTO mapping using MAPSTRUCT. It seems that I did everything according to the guide, but an error is issued. What is the problem, I cannot understand. There is very…
Artur Vartanyan
  • 589
  • 3
  • 10
  • 35
21
votes
2 answers

Spring DTO validation in Service or Controller?

I'm building a straight forward AJAX / JSON web service with Spring. The common data flow is: some DTO from browser v Spring @Controller method v Spring @Service method I'm looking for the most easy way to handle…
Benjamin M
  • 23,599
  • 32
  • 121
  • 201