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
42
votes
5 answers

Value Objects in CQRS - where to use

Let's say we have CQRS-inspired architecture, with components such as Commands, Domain Model, Domain Events, Read Model DTOs. Of course, we can use Value Objects in our Domain Model. My question is, should they also be used…
driushkin
  • 3,531
  • 1
  • 24
  • 25
38
votes
4 answers

Which layer should be used for conversion to DTO from Domain Object

We are creating rest api's with Spring Boot. We have three layers in our project(Repository, Service and Controller). Lets say I have GetUser api in my controller that return UserDTO object. @GetMapping public UserDTO getUser() { return…
Suleyman Arıkan
  • 503
  • 1
  • 4
  • 7
35
votes
9 answers

Nullable reference type in C#8 when using DTO classes with an ORM

I activated this feature in a project having data transfer object (DTO) classes, as given below: public class Connection { public string ServiceUrl { get; set; } public string? UserName { get; set; } public string?…
M.Hassan
  • 10,282
  • 5
  • 65
  • 84
34
votes
8 answers

Mapping Validation Attributes From Domain Entity to DTO

I have a standard Domain Layer entity: public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set;} } which has some kind of validation attributes applied: public class…
Martin Suchanek
  • 3,006
  • 6
  • 31
  • 31
33
votes
7 answers

DTOs: best practices

I am considering to use DTOs instead of passing around my domain objects. I have read several posts here as well as elsewhere, and i understand there are several approaches to getting this done. If i only have about 10 domain classes in all, and…
LiveDotNet
32
votes
5 answers

C# MongoDB: How to correctly map a domain object?

I recently started reading Evans' Domain-Driven design book and started a small sample project to get some experience in DDD. At the same time I wanted to learn more about MongoDB and started to replace my SQL EF4 repositories with MongoDB and the…
hoetz
  • 2,368
  • 4
  • 26
  • 58
32
votes
3 answers

How to use ModelMapper for deep inheritance objects?

A.java @Entity @Getter @Setter @Inheritance @JsonTypeInfo(use=JsonTypeInfo.Id.NAME, inclue=JsonTypeInfo.As.PROPERTY, property="type") @JsonSubTypes({ @JsonSubTypes.Type(value=AA.class,name="aa"), …
Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73
32
votes
5 answers

Domain vs DTO vs ViewModel - How and When to use them?

In a Multi-layer project with Domain layer (DL)/Business (Service) Layer (BL)/Presentation Layer (PL), what is the best approach to deliver Entities to the Presentation Layer? DO => Domain Object; DTO = Domain Transfer Object; VM => View Model; V =>…
Patrick
  • 2,995
  • 14
  • 64
  • 125
30
votes
8 answers

What is the difference between POJO (Plain Old Java Object) and DTO (Data Transfer Object)?

I cannot find difference between them. Does anyone know how to differentiate them?
d1ck50n
  • 1,331
  • 2
  • 16
  • 20
29
votes
5 answers

How to quickly check if two data transfer objects have equal properties in C#?

I have these data transfer objects: public class Report { public int Id { get; set; } public int ProjectId { get; set; } //and so on for many, many properties. } I don't want to write public bool areEqual(Report a, Report b) { if…
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
29
votes
6 answers

Python: Quick and dirty datatypes (DTO)

Very often, I find myself coding trivial datatypes like class Pruefer: def __init__(self, ident, maxNum=float('inf'), name=""): self.ident = ident self.maxNum = maxNum self.name = name While this is very useful…
Jo So
  • 25,005
  • 6
  • 42
  • 59
28
votes
2 answers

Same/different DTO object in create, update and get rest end points?

Consider following UserDTO class and UserController exposing endpoints to create, update and get User. Having the id property in the UserDTO class does not make sense for create and update. If I use swagger or another auto generated API…
Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
28
votes
6 answers

DTO classes vs. struct

So, this is actually this question is my current keystone. I'm working on refactoring of my personal project, trying increase performance, optimize memory usage, make code easy and clear. I have a different application layers (actually, DAL, BLL,…
Andriy Zakharko
  • 1,623
  • 2
  • 16
  • 37
26
votes
4 answers

What is the best practice for sending data to the client: POCO or DTO?

I'm starting a project using EF 4 and POCO. What is the best practice for sending data to the client ? Should I send the POCO or I should have a DTO instead? Are there any issue I should be aware of when sending the entity (that is disconnected…
pdiddy
  • 6,217
  • 10
  • 50
  • 111
26
votes
2 answers

What is the difference between DAL, DTO and DAO in a 3 tier architecture style including with MVC

Recently I was learning about ORM (Object Relational Mapping) and the 3 tier architecture style (presentation,business and data persistence). If I understand correctly, I can separate the data persistence layer into DTO and DAO layer. I would like…
Bálint Pap
  • 498
  • 2
  • 12
  • 23