MVC Using Domain Models in View Models

前端 未结 3 1675
长情又很酷
长情又很酷 2021-01-04 11:47

Is the following OK to do? I know Domain Models should never be used in views but is it ok to use Domain Models in your View Models? For some very small models it doesn\'t s

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 12:12

    Personally I use domain models in the view if they would naturally be an exact fit. That is likely to happen only on trivial projects that are CRUD in nature (editing the domain entities in a straightforward way). I find it a waste of time to create an exact copy of a domain entity for the sake of purity.

    I will never modify a domain model in the slightest to account for needs of the view. In 95%+ of my projects, this is the circumstance I find myself in. The moment you pollute the domain for the sake of the view, you introduce maintainability headaches.

提交回复
热议问题