开发者

DTOs : Several DTO (and Assemblers) for the same resource

开发者 https://www.devze.com 2022-12-17 02:41 出处:网络
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 f

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 a开发者_JS百科n 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消