DTO:同一资源的多个 DTO(和汇编器)

发布于 2024-08-18 21:28:26 字数 256 浏览 1 评论 0原文

根据具体情况,我经常需要为同一个资源使用多个 DTO。

以相册为例。根据我想要显示的内容,我需要在 DTO 中添加不同的数据(通过表单、列表、详细信息等创建)。

我将有一个 albumFormDTO 来创建相册,一个 albumDTO 集合用于创建相册列表,以及一个 albumDetailDTO 来创建详细相册。

对于每个,我都需要一个特定的汇编器。这样做似乎真的很沉重。

是不是看起来很傻?

谢谢, 西亚·本杰明.

I often need, depending on cases, of several DTOs for a same resource.

Take the example of photo Albums. Depending of what i want to display, i'll need different data into my DTOs (creation thru a form, list, details, etc.).

I will have an albumFormDTO to create an album, an albumDTO collection for a list of albums, and an albumDetailDTO for a detailed album.

For each, i need a specific assembler. It seems really heavy of doing it that way.

Does it seem stupid ?

Thanks,
Cya Benjamin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2024-08-25 21:28:26

不,听起来并不愚蠢。

您建议的替代方法是创建一个用于多种目的的“super-dto”。并且仅一些字段用于每个目的。

随着 dto 变得越来越大,并且不清楚哪些字段对于哪个目的是必要的,这很快就会变得丑陋且难以维护。很难重构,也很难理解。

Nope, doesn't sound stupid.

The alternative to what you suggested is creating a "super-dto" which is used for multiple purposes. and on which only some fields are used for each purpose.

This quickly becomes ugly and unmaintainable, as the dto grows large and it becomes unclear which fields are necessary for which purpose. It is hard to refactor and difficult to understand.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文