A lot of our architecture is orientated around Commands ICommandHandler. We post a Command model to the controller action. The command/model is then validated in each action by running validator (if it is found by DI) of ICommandValidator.The ModelState is then updated by merging errors returned from IComamndValidator.
The command validator is part of the Domain Model project (and have various implementations depending on the client/feature enabled etc). We want to use the validators from the domain model as they are used in the non MVC side of the project as well.
Does anyone know an extension point that we can hook in ICommandValidator to get them to run before the action starts. I have seen ModelValidatorProviders but didn't seem what we needed. We want to inject a command validator (if it exists), run the validator, and update the ModelState before the action starts. Using a filter etc didn't seem right as I assume there is an extension point I am missing/misunderstanding.
Any ideas appreciated
Try the OnActionExecuting
event.
Assuming you have a base controller, you could override that event in there and it will fire on each of your derived controllers before an action is executing.