To use or not to use Data transfer objects(DTO) in a Web Api Chat Application Backend Server

爱⌒轻易说出口 提交于 2019-12-01 03:14:57

Yes, you can expose your entities if this is a small application developed by one person and you only have few days to finish it.

If you intend to build an application that may grow up in the future, you should consider using DTO because Domain Entities is not optimal for representation of data. Domain Entities always have more or less, not exactly what you need on the client side.

You can use a tool called AutoMapper to map Domain Entities to DTO.

Some demo: http://www.codeproject.com/Articles/61629/AutoMapper

Tony Hopkinson

Same advantage as in any other application. There's no specific advantage in your app. Using DTO's is essentially a decoupling exercise, segregating properties from methods. At the moment you are passing database objects. Doing that could mean you are passing more than required and exposing more than needed. You are also implying a great deal, what and how operations are carried out. There again what are you are going to get out of the effort of splitting things up?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!