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

Constructing an object graph from a flat DTO using visitor pattern

I've written myself a nice simple little domain model, with an object graph that looks like this: -- Customer -- Name : Name -- Account : CustomerAccount -- HomeAddress : PostalAddress -- InvoiceAddress : PostalAddress --…
MattDavey
  • 8,897
  • 3
  • 31
  • 54
12
votes
2 answers

Should a DTO/POCO have a constructor and private setters on all properties?

I know there are many discussions here about DTOs and POCOs, but I couldn't really find one about this. Is there a rule on writing DTOs without constructors vs private setters and constructors? Example A: public class Person { public int Id {…
gcbs_fln
  • 333
  • 2
  • 10
12
votes
1 answer

How do you map a Dto to an existing object instance with nested objects using AutoMapper?

I have the following Dto and entity with a nested sub entity. public class Dto { public string Property { get; set; } public string SubProperty { get; set; } } public class Entity { public string Property { get; set; } public…
John Mills
  • 10,020
  • 12
  • 74
  • 121
12
votes
1 answer

Should i use builder pattern in DTO?

This might be a pretty subjetive question, but i would to know some more opinions. I've built a Rest API service with Spring MVC, and i implemented the DTO-Domain-Entity pattern. I want to know what do you think about implementing the Builder…
jscherman
  • 5,839
  • 14
  • 46
  • 88
12
votes
3 answers

How to use Dozer with Spring Boot?

I am working on a Spring Boot project. I just have annotation configuration. I want to include dozer to transform Entities to DTO and DTO to Entities. I see in the dozer website, they explain i have to add the following configuration in spring xml…
Pracede
  • 4,226
  • 16
  • 65
  • 110
12
votes
3 answers

Using Automapper, mapping DTOs back to Entity Framework including referenced entities

I've got POCO domain entities that are persisted using Entity Framework 5. They are obtained from the DbContext using a repository pattern and are exposed to a RESTful MVC WebApi application through a UoW pattern. The POCO entities are proxies and…
12
votes
4 answers

What is the best way to mock DTOs in Java?

When writing unit tests I need some objects with sample data. For example suppose I have an Order object. One needs to write code like this - Order o = new Order(); o.setId(3); o.setAmount(2830.9); List items = new ArrayList(); Item i…
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
12
votes
1 answer

DTO Pattern + Lazy Loading + Entity Framework + ASP.Net MVC + Auto Mapper

Firstly, Sorry For lengthy question but I have to give some underlying information. We are creating an Application which uses ASP.net MVC, JQuery Templates, Entity Framework, WCF and we used POCO as our domain layer. In our application, there is a…
marvelTracker
  • 4,691
  • 3
  • 37
  • 49
11
votes
3 answers

List differences: DTO, VO, Entity, Domain, Model

Now I study about the Spring Boot that with JAVA platform. A problem I faced is how can you tell the difference between DTO, VO, Entity, Domain, and Model. Honestly it all look too similar to tell the difference. I already checked some stackoverflow…
Sangwoo Park
  • 137
  • 1
  • 1
  • 5
11
votes
3 answers

NestJS transform a property using ValidationPipe before validation execution during DTO creation

I'm using the built in NestJS ValidationPipe along with class-validator and class-transformer to validate and sanitize inbound JSON body payloads. One scenario I'm facing is a mixture of upper and lower case property names in the inbound JSON…
BSmith
  • 163
  • 1
  • 1
  • 7
11
votes
1 answer

Nest.js only accept fields that are specified in a DTO

I'm currently playing around with Nest.js and have a simple app with a route to register accounts. I created a DTO with a few fields as well as a mongodb schema. There is exactly one field in the mongodb schema I don't want to let a user modify on…
Blade
  • 477
  • 1
  • 7
  • 18
11
votes
5 answers

Entity Framework and DTO

Im planning to use the Entities generated by the EF (POCO) in sending data to the client instead of creating DTOs? Is this a good practice? Basically, my EDMX file is on my DAL layer. So the UI will have direct access on my DAL. Thanks.
dotnetlinc
  • 391
  • 3
  • 7
  • 18
11
votes
4 answers

spring boot data @query to DTO

I want to assign the result of a query to a DTO object. The DTO looks like this: @Getter @Setter @NoArgsConstructor public class Metric { private int share; private int shareholder; public Metric(int share, int shareholder) { …
btinsae
  • 503
  • 2
  • 5
  • 13
11
votes
4 answers

How to manually mapping DTO WITHOUT using AutoMapper?

I'm learning C#.NET Core and trying to create DTO mapping without using AutoMapper as I'm working on a small project alone and want to understand fundamental before using extra packages, surpringly I could not easily find answer at stackoverflow.com…
user10268539
  • 149
  • 1
  • 1
  • 11
11
votes
2 answers

What Project Layer Should Screen DTO's Live In?

I have a project where we use screen DTO's to encapsulate the data between the Service Layer and the Presentation Layer. In our case, the presentation layer is ASP.Net. The only classes that know about the DTO's are the service layer classes and the…
Scott Muc
  • 2,873
  • 27
  • 38