What Project Layer Should Screen DTO's Live In?

后端 未结 2 1850
梦谈多话
梦谈多话 2021-02-01 09:26

I have a project where we use screen DTO\'s to encapsulate the data between the Service Layer and the Presentation Layer. In our case, the pres

2条回答
  •  爱一瞬间的悲伤
    2021-02-01 09:59

    Even thought the canonical use-case for the 'DTO' is more "serializable object that can be passed over the wire", in this case you are really referring more to 'presentation-transfer-objects' or 'view-models'.

    Typically for our projects the answer to where these live is where the 'translation' code is that maps the DDD domain model to the PTO classes. If that's in the Prensenation layer (perhaps not so great an answer) then the pres. layer is where I'd declare the PTOs. But more often than not, its the 'Service' that does the translation for you and that means that both the 'Service' and the 'Presentation' layer need references to the PTOs and that (usually) leads to their declaration in a separate, neutral project/assembly/namespace/whatever that BOTH the presentation layer AND the service layer can then reference.

提交回复
热议问题