fluentvalidation - ServiceStack httpReq.TryResolve<IValidator<T>>(); not resolving correctly? -


i implementing own user registration service based on built in registrationservice, have copied of including first few lines below...

        if (endpointhost.requestfilters == null             || !endpointhost.requestfilters.contains(validationfilters.requestfilter)) //already gets run             registrationvalidator.validateandthrow(request, applyto.post);           // above line not hit there validationfilters.requestfilter         //...but code should have run validation , failed?         //...adding following line causes validation run , fail when expected        //...but should not required point of global validationfilters.requestfilter??         registrationvalidator.validateandthrow(request, applyto.post); 

from understand validationfilters.requestfilter should have been hit earlier , validation exception thrown.

n.b: have put line @ end of apphost configuration.

plugins.add(new validationfeature()); 

and registering validator, this:

container.register<abstractvalidator<userregistration>>(new userregistrationvalidator()); 

...i have narrowed down 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 not finding validator.

i figured out validators not resolving ioc container...rather delve took step , instead found out why automatic registration method did not work me previously.

the reason had this...

public interface iuserregistrationvalidator : ivalidator<userregistration> { }  public class userregistrationvalidator : abstractvalidator<userregistration>, iuserregistrationvalidator { //..etc 

and servicestack code tripping on line shown below obvious reasons (suggest friendly exception):

    public static void registervalidator(this container container, type validator, reusescope scope=reusescope.none)     {         var basetype = validator.basetype;         while (!basetype.isgenerictype) // fail on line here         {             basetype = basetype.basetype;         }          var dtotype = basetype.getgenericarguments()[0];         var validatortype = typeof(ivalidator<>).makegenerictype(dtotype);          container.registerautowiredtype(validator, validatortype, scope);     } 

after getting rid of pointless interfaces playing around can use automatic method of registering validators...such as:

container.registervalidators(typeof(userregistrationvalidator).assembly); 

which resolves issues, not 100% sure how manually register uservalidator https://github.com/servicestack/servicestack/wiki/validation , have work still under impression following not work properly.

container.register<abstractvalidator<user>>(new uservalidator()); 

...i wrong of course!


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -