Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

You can see the extension points for MVC by doing the following:

Open Global.asax | right-click on HttpApplication | Go to Definition

Here is a good review of the MVC 4 Request Pipeline:

http://jameschambers.com/blog/a-web-developer-s-look-at-the-mvc4-request-pipeline

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top