I am implementing my own user registration service based on the built in RegistrationService, so I have copied most of it including the first few lines below...
if (EndpointHost.RequestFilters == null
|| !EndpointHost.RequestFilters.Contains(ValidationFilters.RequestFilter)) //Already gets run
RegistrationValidator.ValidateAndThrow(request, ApplyTo.Post);
// Above line does not get hit as there is the ValidationFilters.RequestFilter
//...but then the code should have previously run validation and failed?
//...Adding the following line causes the validation to run and fail when expected
//...but I should not required it as that is the point of the global ValidationFilters.RequestFilter??
RegistrationValidator.ValidateAndThrow(request, ApplyTo.Post);
From what I understand the ValidationFilters.RequestFilter should have been hit earlier and my validation exception thrown.
N.B: I have put this line at the very end of my apphost configuration.
Plugins.Add(new ValidationFeature());
And I am successfully registering my validator, with this:
container.Register<AbstractValidator<UserRegistration>>(new UserRegistrationValidator());
...I have now narrowed it down to the following lines of ServiceStack source code in ValidatorCache.cs
public class ValidatorCache<T>
{
public static IValidator GetValidator(IHttpRequest httpReq)
{
return httpReq.TryResolve<IValidator<T>>();
}
}
...The TryResolve is not finding the validator.