使用或无法在网页API的聊天应用后端服务器使用数据传输对象(DTO) [英] To use or not to use Data transfer objects(DTO) in a Web Api Chat Application Backend Server

查看:147
本文介绍了使用或无法在网页API的聊天应用后端服务器使用数据传输对象(DTO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用网页API,其中我直接暴露了几个数据库实体为客户构建一个聊天应用程序后端。我不知道是否有任何积极的指向实体映射到DTO的,或者我应该继续揭露实体目前我。只是为了澄清我不是问了DTO VS非DTO一般性问题,但只是在这种情况下使用它,因为大多数实体领域的优势可能会被客户端使用。

I have a chat application backend built using Web Api where I am exposing several database entities directly to clients. I was wondering whether there is any positive points to map the entities to DTOs or should I continue exposing the entities as I am currently. Just to clarify I am not asking a DTO vs non-DTO general question but just advantages of using it in this scenario since most of the fields in the entities would probably be used by the client.

推荐答案

是的,你可以暴露你的实体,如果这是由一个人开发了一个小的应用程序,你只需要几天才能完成它。

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.

如果你打算建立一个可能在未来成长的应用程序,你应该考虑使用DTO,因为域实体是不是最佳的数据重新presentation。域实体总是有或多或少的,不是你需要在客户端到底是什么。

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.

您可以使用一个名为 AutoMapper 以领域实体映射到DTO工具。

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

一些演示:<一href=\"http://www.$c$cproject.com/Articles/61629/AutoMapper\">http://www.$c$cproject.com/Articles/61629/AutoMapper

这篇关于使用或无法在网页API的聊天应用后端服务器使用数据传输对象(DTO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆