Home > Enterprise >  Where should DTO conversion be done in MVC?
Where should DTO conversion be done in MVC?

Time:09-10

Where should DTO conversion be done in MVC?

I am using JPA. Receive DTO as parameter from Controller.

At this time, is it necessary to convert it in the controller and pass it to the service?

Or, I wonder if the service receives the DTO and converts it.

CodePudding user response:

I think do the conversion in the controller is the better way. Because the service just contain business logic using domain entity not DTO.

Based on my experience, the codes on service layer can be very complex. If you add the conversion DTO logic to it, it will make the service even more difficult to develop, because the service is depend on DTO, so you must know the structure of DTO too and its converter method work.

CodePudding user response:

I use DTO in service layer . because service must contain business logic . controller is just a middleware between processing data and show the result to user so It seems reasonable to map DTO to your entity in service

  • Related