Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bestpractice - Mixing View Model with Domain Model

Is it reasonable to mix view models with domain models?

So i.e. the view model object contains some domain model objects (not the other way around!)

like image 928
Rookian Avatar asked Feb 04 '23 04:02

Rookian


1 Answers

Generally, you will have to reference your Domain Models in your View Models, or at least load the Domain Models in the controllers and pass the information on to your View Model.

I prefer to keep Controllers and Views as simple/dumb as possible, because both Domain Models and View Models are FAR easier to test.

So, I often reference my Domain Models inside my View Models. Sometimes I use aggregation, sometimes I just copy over properties (In some projects just with plain old code, in other projects using an auto mapper)

like image 167
CubanX Avatar answered Feb 05 '23 16:02

CubanX