asp.net - Passing ViewModel from Presentation to Service - Is it Okay? -
in 1 of views, have viewmodel
populate 2 tables, , bind list<viewmodel>
editable gridview (asp.net web forms).
now need send edited list<viewmodel>
services layer update in database.
my question - okay send viewmodel services, or should stay in presentation? if not - should better use dto? many thanks.
nice question !
after several (hard) debates teammates + experience mvc applications, not recommend pass viewmodel service / domain layer.
- viewmodel belongs presentation, no matter what.
- because viewmodel can combination of different models (e.g : 1 viewmodel built 10 models), service layer should work domain entities.
otherwise, service layer end unusable because constrained viewmodels specifics 1 view.
nice tools https://github.com/automapper/automapper made make mapping job.
Comments
Post a Comment