Where to handle mapping between DTOs and Entity objects?
Lets say I have controller GET /users/ which returns UserDTO. Where would I do this mapping between User and UserDTO?
- In controller: userService.GetUsers -> transform to UserDTO list -> return list
- in service: Method UserService.GetUsers does the mapping and returns UserDTO list
- in separate service: I have two methods in my service: GetUsers (which returns Entity objects) and GetUsersDTO (which calls GetUsers method and map it)
- anything else?
3 Replies
Unknown User•7d ago
Message Not Public
Sign In & Join Server To View
yeah id make it an extension method, and probably in its own class that handles mapping it depends on the arch
You could do the projection in the database side and already return the response/dto from your service