0 votes
by (2 points)
edited

Convert DTO in essence: where better to do so, the classical architecture of web applications?. Controller service mapper (which mapit dto the spirit and back). In a layer need zaavtovayrit mapper and convert dto the essence and vice versa. There are two podhoda.Preobrazovanie in the controller. Thus, the service is already taking the essence of all dependencies and returns the entity (which again is converted to a controller in the dto and sent, for example, to the front). For this approach the consideration that dto is data obtained from the outside, and therefore, it must be converted into the essence as soon as possible and go to the other layers already in the form of essence. Also, for this approach serve those frequent occasions when we need to get the essence And when B. Then B when we avtovayrim service A, go to the service ID And the essence and get the essence, but the service gives dto, and here it converts received dto in essence, which is returned to service B, and there occurs reverse transformation dto in essence, with the filling of dependency and hikes in the base. Or do we have to write a second any public Car get (Long id) method in addition to the public CarDto get (Long id). Which is not easy when kod.Preobrazovanie. This approach involves the use of essentially only to operate the repository. Plus approach that dto much easier in terms of the essence of dependency, and to drive it between the services much easier, and work with dto much easier. You do not need to worry about data consistency, lazy initialization and other intricacies of working with entities. As well, it allows you to monitor all requests to the database, if we needed a relationship, we just take it according dto, thus avoiding, when for int-field have to pull from the database all the essence of the tree of dependencies and store it in pamyati.Itak, gentlemen, I want to hear your voice on this schot.Vyacheslav Chernyshov

1 Answer

0 votes
by (2 points)
edited
As for me the conversion should take place on the level of service, because in my opinion the essence of the objects do not have to return the service. More as an argument, I can say that it is recommended to use the declarative transaction management is at the service level. Which in turn is very much related to the work with entities
Welcome to askiry.com, where you can ask questions and receive answers from other members of the community.
...