jeudi 16 juin 2016

DDD: Best way to build View models/DTO

Let's assume that I have some entity with many properties and repository to retrieve it. I want to show list of these entities to users, but I only need 3 properties. I can map retrieved entity to needed ViewModel/DTO in application service layer, but then I would get too much data from database which is suboptimal. Alternatively I can make some specific methods in entity repository like GetXXXViewModel() and retrieve only what is needed and map it directly to viewmodel (using dedicated query or projection). But then I would pollute my infrastructure/persistence layer with UI concerns. What's the best practice for resolving this?

Aucun commentaire:

Enregistrer un commentaire