ServiceStack/ServiceStack — pull request #126 by pauldbau (2012-04-06 05:27:06+00:00)
Title: Fixed issue with FunqValidatorFactory (ServiceStack.FluentValidation) not working in ordinary MVC3 scenarios

The issue was traced to using straight Resolve in the ContainerResolveCache.
When Resolve fails, it throws an exception, which in turn crashes MVC3 validation through the FunqValidatorFactory.
Instead of just wrapping the ContainerResolveCache.CreateInstance with a try catch to suppress the error, rather modified ContainerResolveCache to accomodate running in TryResolve mode as well as the existing Resolve mode. Then used the TryResolve mode in FunqValidatorFactory.

Also renamed FunqValidatorBase.cs to now match the class it contains - i.e. FunqValidatorFactory

To simulate the error that this commit fixes, add the following to AppHost.Configure and then run the default MVC3 site.
It should crash at the LogOn page (since there is Required validation on the LogOnModel).

// Configure FluentValidation to use Funq injected validator factory
// and hook FV into MVC framework
var factory = new FunqValidatorFactory(container);
FluentValidationModelValidatorProvider.Configure(provider => provider.ValidatorFactory = factory);
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;