i have an application that use the MVVM pattern and I would like to implement validation when the user is fill the information.
I would like to use the IDataErrorInfo, but I don't know if it is a good idea that my view model implements that interface or if it is better that I create a new class. How is the best way to imlpement validantion with IDataErrorInfo and the MVVM pattern?
EDIT: I see that in some examples the implementation is in the model (it is not the same than the view model), but in my case the model basically is the POCO entities that I create from my database when I create my edmx model with entity framework, so I would like to avoid the needed to modify this entities because if I need no update my model, I would have to do the work again.
Thanks.
IDataErrorInfo
. That interface pretty much "assists" with passing information to the User(View) for background errors(Errors in Data). that's exactly what the VM is for and it'd be perfectly valid to have it there. Comments in this answer and the one below it argue with having it in the Model. Having it defined in another class is than the Model and the VM wouldn't be "wrong" either for abstraction but might just not be worth it. – SitterIDataErrorInfo
is such complicated logic that you'd want to re-use it, then I'd literally move those functional checks into a service and then have the VM implement the interface and in the VM use the service to access the complicated validation logic. That way you got your code-reuse and sharing and also stay clean and simple with each VM just implementing theIDataErrorInfo
themselves – Sitter