Featured post
asp.net mvc - Domain object validation vs view model validation -
i using asp.net mvc 3 , using fluentvalidation validate view models. little concerned might not on correct track. far know, model validation should done on domain object. mvc might have multiple view models similar needs validation. happens if property domain object occurs in more 1 view model? validating same property twice, , might not in sync. if have user domain object validation on object. happens if have useraviewmodel , userbviewmodel, multiple validations needs done.
in news class have property called title, required field. on view model have title property, use automapper map news , newsviewmodel. validation happening twice. when domain model validation occur , when view model validation occur?
the scenario above example, please don't critise on it.
it's subtle distinction validation on view model validate correct user input , forms anti-corruption layer domain model, whereas "validation" on domain model enforces business rules. normal , should have validation on both layers. in fact may feasible useraviewmodel has different input validation userbviewmodel. question, try avoid exposing domain objects through viewmodel , instead map between them (often using automapper), way viewmodels anticorruption layers rather property bags of domain models. hope helps.
- Get link
- X
- Other Apps
Comments
Post a Comment