Should the repository layer return data-transfer-objects (DTO)?

前端 未结 2 1978
小蘑菇
小蘑菇 2020-11-30 00:19

I have a repository layer that is responsible for my data-access, which is called by a service layer. The service layer returns DTOs which are serialized and sent over the w

2条回答
  •  无人及你
    2020-11-30 00:24

    Short answer: No.

    Long answer: repository is responsible for turning persisted data back to entities (models) and vice versa.

    Model is a business Model representing a business entity. DTO on the other hand - while looks like Model - is concerned with transfer of the object between various environment and in essence is a transient object. Usually mappers are responsible for turning model into DTO.

提交回复
热议问题