I am trying to verify user input, in particular user passwords. I have a jQuery validation, but of course I also need to check on the server side. Now my request comes to the controller, which will pass it on UserService. Everything is loosely connected, so the controller really does not know too much about the inside UserService. Now suppose the user has entered a weak password, so I need to tell him "hey, this is not enough."
Question: how can this be done?
Somehow I need to call
ModelState.AddModelError(field, exception);
to indicate what went wrong, where and why - in a simple example I already know the password, because this is really the only field in the form, but in general it is not so simple. Now I was close to writing my own type Exceptionto do something like
ModelState.AddModelError(ex.Field, ex.Message);, where I may need additional matching, which is necessary for the path adopted by NerdDinner, where they have it RuleViolations.
However, at NerdDinner, the business object is self-justified. In this case, this is not the best way, because the "business object" here is just a store for email and password that it implements IIdentity. It should not know anything about the length of the password and should be reused for different applications.
, ArgumentException ValidationException, , , , DataAnnotations.
, , . , - ?