ninject / Ninject.Web.Mvc.FluentValidation

Fluent validation extension for ninject.web.mvc
13 stars 6 forks source link

setting up ninject.web.mvc.fluentvalidation is not straight forward #6

Open menaheme opened 10 years ago

menaheme commented 10 years ago

Hi , First of all, i am very grateful for all the work put in the Ninject project and its extensions.

to the issues: using MVC4 on VC2012 Pro, wanting Ninject + FluentValidation

  1. installed the ninject MVC3 and fluent validation mvc4 + the ninject fluent validation extension, all using nuget. since using only stable versions, i ran into the signing issue as seen here , i would like very much for the package from nuget to work without the workaround.
  2. i used a single simple model object with nothing on it but auto props. added a simple validator class using AbstactValidator, with a single simple RuleFor rule. running with F5 , didnt activate the validator. (i saw the instructions but they are not clear as to where to put the first snippet marked "1" , and the NinjectModule (also marked "1") is never loaded, by anyone.)
    google around for quite a bit got me here, and now the validator gets loaded. i think the nuget should also put the code linked above, in the proper places, especially the NinjectModule and add it to the the kernel`s initialization. the problem is that installing the extension leaves you half way through, and its not so easy to complete the task.
  3. now that the validator is loaded, i get the dreaded "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required", as answered by Remo Gloor here. it still does not work for me (Remo`s answer does not work for me, the AttributeValidatorProvider class is not in any referenced assembly). Again i think it should work right after installing the Nuget and hitting F5.

there`r a lot of question at StackOverflow on all 3 points, so im not the only one having a hard time.

i would very much appreciate your response.

rexcfnghk commented 9 years ago

Is anyone following up with this? Is it ok if I have a go and try to update the documentaion? I am thinking of introduce a new dependency (through NuGet) on Ninject.Web.Common so that NinjectValidatorFactory can be set up in Global.asax.cs like this:

protected void Application_Start()
{
    var kernel = DependendencyResolver.Current.GetService<IKernel>();
    var ninjectValidatorFacotry = new NinjectValidatorFactory(kernel);
    ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(ninjectValidatorFactory));
    DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
}

Is this solution acceptable?

ciaran036 commented 6 years ago

Anyone got a complete guide to configuring Ninject with FluentValidation?