Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

DTOs vs ViewModels #2581


User avatar
0
apexdodge created

Reading this documentation here: <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Data-Transfer-Objects">http://aspnetboilerplate.com/Pages/Docu ... er-Objects</a>

It is recommended to always use a DTO for input and output for all application service methods. That is fine, despite the groans from my devs about the added work -- I see the benefits.

My question is about ViewModels.

Should we have ViewModel for every DTO as well? Or is it common practice to send the DTO straight to the end user in the presentation layer?

Likewise for accepting data -- Should a form submission go to a ViewModel first, which is then mapped to a DTO, which is then mapped to an Entity. Or do form submissions go straight to DTO?

Any reasoning for either option would be much appreciated.

Thanks.


1 Answer(s)
  • User Avatar
    0
    bilalhaidar created

    Hi,

    I am currently using the framework with Angular js 1.x.

    By default, the framework would generate Web API proxies for all those objects that implemented IAppService.

    Therefore, I use the proxy on the client side to call any method defined on the ApplicationSevice layer using only DTOs.

    Generally speaking, DTO is more or less a ViewModel.

    HTH, Bilal