c# - Wiring up fluentvalidation with Nancy and Ninject -
i using nancy ninject ioc. fine. need add fluentvalidation. how go wiring nancy use fluentvalidation via ninject?
i see there's nuget package ninject.fluent.validation can't find documentation or example on how use it.
the demo project on nancyfx website uses tinyioc it's not useful me.
update: have tried do:
var createrequest = this.bindandvalidate<createrequest>(); if (!modelvalidationresult.isvalid) { return response.asjson(modelvalidationresult, httpstatuscode.badrequest); }
the model valid (even if there should errors reported createconsumerrequestvalidator
).
this have added in ninject bootstrapper:
bind<imodelvalidatorfactory>().to<fluentvalidationvalidatorfactory>().insingletonscope(); assemblyscanner.findvalidatorsinassemblycontaining<createrequestvalidator>() .foreach(match => bind(match.interfacetype).to(match.validatortype));
the imodelvalidatorfactory wired automatically nancy v0.12 (see here configure nancyfx fluent validation) - need wire validators.
this works nancy 0.23
using fluentvalidation; using ninject.extensions.conventions; using ninject.modules; public class validatormodule : ninjectmodule { public override void load() { this.kernel.bind( x => x.fromassembliesmatching("yournamespace.*") .selectallclasses() .inheritedfrom<ivalidator>() .bindallinterfaces()); } }
Comments
Post a Comment