Difference VO (model view) of the DTO (data transfer object)

Difference VO (model view) of the DTO (data transfer object)


1.VO concept and DTO

VO (View Object): VO is a view of the model, the view object for display layer, it is the role of a given page (or component) of all of the data package together. Example: Display layer displayed as DTO transmitted from male guy (a client), or displayed as a handsome (Client 2); or the guy handsome, male converted to the server requesting the form of DTO.

DTO (Data Transfer Object): DTO is the transmission model data transfer objects, where an object refers to the data transmission between the service layer and the presentation layer. Accept the male sex show floor pass, returning male gender presentation layer.


Necessity and decoupling 2.VO view of the model

2.1 view model

In the present display layer.

Necessity of the view model 2.2

VO model view may correspond to the client's web page display, such as gender Male same DTO, VO may correspond to a plurality of displays, i.e. may correspond to a plurality of clients, such as shown as male gender VO1 guy, shown as male gender of VO2 like handsome Wait.

Decoupling view of the model 2.3

If it corresponds to a DTO a VO, the VO = DTO; however, if a corresponding number of DTO VO, the VO presentation layer needs to be converted to the corresponding service layer method as claimed in DTO, to the service layer. So as to achieve the service layer and the presentation layer decoupled.


The need exists 3.DTO

3.1 Data Transfer Object

Json array may correspond to a DTO DO (Domain Object, the domain model) returned from a plurality of storage layers, may be used herein to AutoMapper self-adapting.

3.2 DTO necessity of data transfer object

DTO is not a view MVC model exists, but in order to meet a request from the front end exists. DTO model the request (the request from the front end of the separation regardless of the page, a page view or mvc) from the front end of the package in the DTO model, and then converted into a processing server model Entity Framework in the art.


The difference between the DTO and 4. VO

4.1 DTO = view model

In a DTO time corresponding to a VO, DTO = view model. Property values DTO and VO is basically the same, and they are usually json objects, so no need to bother, but do not forget that this is achieved the level of thinking, the design level, or should exist VO and DTO on the concept, because both are essentially different, DTO represents the service layer needs to receive the data and return data, and data presentation layer represents the VO to be displayed.
Application, the DTO may pack into the front end of VO, Controller layer service may be terminated, service layer packet into VO. Similarly VO converted DTO.
In this case can be achieved, something related to the front and rear end of the url and only api vo, but in most cases is only a client.

4.2 DTO ≠ view model

DTO when In one of the corresponding plurality of VO, DTO ≠ view model. At this time, the leading end needs to be packaged into male or guy handsome display; data is requested, the front end also needs to convert into a handsome guy or male, in the form of DTO requesting server.

5. AutoMapper usage scenarios

Many online description of the methods used AutoMapper, not described here, referring to the next major usage scenarios.
AutoMapper is a mapping between the DTO model and domain model. AutoMapper DTO model conversion process and the field model. The usual practice is: DTO model C contains domain model A corresponding DTO model A and the domain model B corresponding DTO Model B, then the server, respectively, the DTO models A and DTO model B by AutoMapper converted into a domain model A and Domain model B.

//比如视图模型:

public class PersonViewModel
{
     public string FirstName{get;set;}
     public string LastName{get;set;}
}

//比如领域模型:

public class Person
{
     public string Name{get;set;}
}

//领域模型在上下文中:

public class MyDbContext : DbContext
{
     public DbSet<Person> Persons{get;set;}
}

6. Summary

1.DTO is the object of the data transfer, focusing on "transfer" Where: presentation layer and application layer, as long as the data exchange between presentation layer and application layer, are Dto.
2.1 DTO correspond to the case where a client, DTO = view model; DTO a case corresponding to the plurality of clients, DTO ≠ view model;

Guess you like

Origin www.cnblogs.com/JerryMouseLi/p/11069237.html