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
21
votes
4 answers

Where to convert a DTO to ViewModel?

I've inherited an MVC2 project using a pretty standard and decently well kept DDD pattern. I've been doing a lot of reading on the whole DTO/ViewModel debate as well. Currently our DTOs are often used like ViewModels. It honestly doesn't make a…
19
votes
1 answer

How to work with DTO in Spring Data REST projects?

Spring Data REST automates exposing only domain object. But most often we have to deal with Data Transfer Objects. So how to do this in SDR way?
Cepr0
  • 28,144
  • 8
  • 75
  • 101
19
votes
3 answers

Data transfer object pattern

i'm sorry i'm newbie to enterprise application as well as the design pattern. might be this question occcur lack of knowledge about design pattern. i found that its better to use DTO to transfer data. my business entity class as below: public class…
DevT
  • 4,843
  • 16
  • 59
  • 92
19
votes
6 answers

DTOs. Properties or fields?

I need to create some DTO classes to transport our business objects across WCF. Since these are just bags of data with no functionality, is there any reason I can't just use fields, or is there some good reason to expose them properly as…
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
18
votes
2 answers

What is the purpose of a Data Transfer Object in NestJS?

Im struggling with a problem. Im following the documentation of NestJS. The back-end framework for NodeJS. The documentation mentions a DTO (Data Transfer Object). I created a DTO for creating a user: export class CreateUserDto { readonly email:…
18
votes
4 answers

Domain Entities, DTO, and View Models

I have an ASP.NET MVC 2 application with a POCO domain model and an NHibernate repository layer. My domain model has no awareness of my viewmodels so I use automapper to go from viewmodel to entity and vice/versa. When I introduced WCF to my…
Mayo
  • 10,544
  • 6
  • 45
  • 90
18
votes
2 answers

Mapping List from List using mapstruct
Hi I am getting null for List action in DTO while setting it from the Child Source class using mapstruct. Could some help me in resolving this. Please find my code here Entity Class: public class Source { int id; String name; …
bhuvana
  • 181
  • 1
  • 1
  • 3
18
votes
5 answers

Interfaces for DTOs

I am currently at the beginning of developing a large web application mainly containing an Angular SPA and an OData WebAPI that has access to a backend layer. We're at an early stage and have begun to implement the first classes including a…
Simon Linder
  • 3,378
  • 4
  • 32
  • 49
18
votes
2 answers

Best Practice - Multi Layer Architecture and DTOs

After reading some of the Q/As here on Stackoverflow, I am still confused about the correct implementation of DTOs in my web application. My current implementation is a (Java EE based) multi-tier architecture (with persistence, service and…
nils
  • 1,362
  • 1
  • 8
  • 15
18
votes
1 answer

How to organize and name DTOs that are used as Data Contracts in a WCF web service

We are using DTOs as Data Contracts in our WCF web service. The purpose for these DTOs is to expose only the information that is relevant for a specific API method. What I am seeking from you guys is some advise on the best practices here. For…
Sumit Garg
  • 469
  • 1
  • 5
  • 16
17
votes
2 answers

How to manually test input validation with NestJS and class-validator

TLNR: I was trying to test DTO validation in the controller spec instead of in e2e specs, which are precisely crafted for that. McDoniel's answer pointed me to the right direction. I develop a NestJS entrypoint, looking like that: @Post() async…
Bob
  • 1,495
  • 1
  • 19
  • 24
17
votes
1 answer

Does GraphQL obviate Data Transfer Objects?

To my understanding, Data Transfer Objects (DTOs) are typically smallish, flattish, behavior-less, serializable objects whose main advantage is ease of transport across networks. GraphQL has the following facets: encourages serving rich object…
Dan Narsavage
  • 325
  • 3
  • 13
17
votes
3 answers

Automapper custom many-to-one conversion

Automapper Many To One conversion How to convert values of many properties from the source object to a single type in destination object? Can I use in this case Value Resolvers? Or maybe there is better solution? Documentation Here is example from…
Pawel Maga
  • 5,428
  • 3
  • 38
  • 62
17
votes
3 answers

Pattern for JPA: Generating Data Transfer Object DTO from Entity and merging DTO to database

I am looking for a good way to create Data Transfer Objects (DTO) from a JPA Entity and vice versa. I want to send the DTO as JSON to a client, then receive the modified DTO and save it back to the database. It would be the most ease to perform the…
user3170740
  • 171
  • 1
  • 1
  • 3
17
votes
1 answer

Using DTO to transfer data between service layer and UI layer

I've been trying to figure this out for days but there seems to be very little info on this particular subject with ASP.NET MVC. I've been Googling around for days and haven't really been able to figure anything out about this particular issue. I've…
grimurd
  • 2,750
  • 1
  • 24
  • 39