none
Context specific IDataErrorInfo validation RRS feed

  • Question

  • We have a WPF app using the MVVM pattern with code first where we need to use different validations for an entity based upon the context it is being used in.  We could implement IDataErrorInfo on each entity, but we'd prefer not to for 2 reasons.  First is that we've tried to keep our entity classes "clean" and not put a bunch of other code in them.  Second is that any such implementation would get bloated fairly quickly with all the variations of validations we need to have.  We've thought about using some TPH classes to subdivide into the entity classes, which would make the validation block smaller, but that would make the number of classes in our model explode and add in a lot of complexity.

    So is there a pattern we could use which would allow us to inject validations per context?  I found some examples where generic rules are created and injected by a viewmodel into a Validations handler, with the viewmodel implemented IDataErrorInfo and INotifyPropertyChanged, but that property changed doesn't get fired for the properties of an entity, so I can't get that to work.  If there was a way for the viewmodel to tell the entity what validation rules to use, please let me know.

    Monday, August 15, 2011 3:24 AM

All replies