Configure NancyFx with Fluent Validation

2019-02-09 01:15发布

问题:

Is there any configuration code that I have to add in the application Bootstrapper to enable FluentValidation in Nancy?

Following the example from https://github.com/NancyFx/Nancy/tree/master/src/Nancy.Demo.Validation I receive the following exception message when trying to use this.Validate on model: No model validator factory could be located.

I'm using Nancy version 0.11.0.0

回答1:

Are you using one of the Bootstrapper packages (autofac, ninject, unity, windsor, structuremap)? If you are then you need to inherit from the bootstrapper type, override ConfigureApplicationContainer and register the type in the container. If you are using the default bootstrapper then it should wire itself up

With out next release, 0.12, it will wired up automatically no matter what bootstrapper you are using