Is DTO and Automapper really matter in asp ?
Hi, Ive been developing ASP for ova 3 years and learn from the other people conventions
But one of the weirdest thing they all have in common is the DTO and Mapper
+ Why do I have to return a DTO when it's 99% identical to the entity ?
+ Why do I have to use the mapper when the defining a map is just like manual ?
+ Can I just create the DTO that meet my FrontEnd requirement and manually hook all the props just simple c# method ?
4 Replies
Why do I have to return a DTO when it's 99% identical to the entity ?because any changes to your entity will now automatically change your API responses. This might mean sharing private data, or oversharing IDs, or accidental breaking changes
Why do I have to use the mapper when the defining a map is just like manual ?You don't. Mapper is optional.
Can I just create the DTO that meet my FrontEnd requirement and manually hook all the props just simple c# method ?yes.
because any changes to your entity will now automatically change your API responses. This might mean sharing private data, or oversharing IDs, or accidental breaking changes
I still not fully understand this
If you change something in entity you have to go the DTO and change it too
and it mapping complex you might do change the the mapping operation alsoUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
DTO gives you an opportunity to represent your entity in a simpler way too. For example I have things in the DTO which show enums in a nicer way, or formatted dates etc