I am integrating FluentValidation with MVC 5.1.0.0. and trying to use StructureMap but I got an error when I am compiling the code:
Error 5 Assembly 'FluentValidation.Mvc, Version=5.4.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' c:\Users\XXXX\Documents\Visual Studio 2013\Projects\XXXX\packages\FluentValidation.MVC5.5.4.0.0\lib\Net45\FluentValidation.Mvc.dll XXX.Web
How can I resolve this error? I tried to install different versions of StructureMap, and it doesn't work. In my Globals.asax.cs I added this code:
//Configure structuremap
ObjectFactory.Configure(cfg => cfg.AddRegistry(new MyRegistry()));
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
//Configure FV to use StructureMap
var factory = new StructureMapValidatorFactory();
//Tell MVC to use FV for validation
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(factory));
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
Also I have this classes:
using System.Web.Mvc;
using FluentValidation;
using FluentValidationIoC.Controllers;
using FluentValidationIoC.Models;
using StructureMap.Configuration.DSL;
public class MyRegistry : Registry
{
public MyRegistry()
{
For<PersonRepository>().Use<PersonRepository>();
For<HomeController>().Use<HomeController>();
For<IValidator<Person>>()
.Singleton()
.Use<PersonValidator>();
}
}
And
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StructureMap;
namespace Movie.Web.StructureMap
{
using System;
using FluentValidation;
using StructureMap;
public class StructureMapValidatorFactory : ValidatorFactoryBase
{
public override IValidator CreateInstance(Type validatorType)
{
return ObjectFactory.TryGetInstance(validatorType) as IValidator;
}
}
}
Can anyone tell me how to resolve this issue?