Domain vs DTO vs ViewModel - How and When to use them?

asp.net-mvc automapper dto entity-framework viewmodel

Question

What is the most effective method for delivering entities to the Presentation Layer in a multi-layer project with a Domain layer (DL), Business (Service) Layer (BL), and Presentation Layer (PL)?

DO => Domain Object;
DTO = Domain Transfer Object;
VM => View Model;
V => View;

Choice 1:

DL => DO => BL => DTO => PL => VM => V

Although it sounds like the best practice, maintaining this choice would be difficult.

Choice 2:

DL => DO => BL => DTO => PL => V

This choice may not seem like good practice, but because DTOs and VMs are so similar, we can feed the data straight to the view, making it easier to construct and maintain.

I may require less information from the BL for mobile devices, hence I will need a different VM for this specific Layout. Is this approach reliable for many layouts as well?

1
27
7/1/2014 2:01:16 PM

Popular Answer

Passing the DTO to the view is acceptable. Make a ViewModel if the DTO has to be changed or improved. Adding links would be a typical instance. Also acceptable is the ViewModel's use of the DTO as a complicated property.

10
10/13/2012 3:10:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow