Using Castle Windsor with FluentValidation In MVC


Using Castle Windsor with FluentValidation In MVC



I'm working on getting FluentValidation working with Castle Windsor. I already have a wrapper around Castle Windsor. Here is the code for that:

public class ResolveType   {       private static IWindsorContainer _windsorContainer;        public static void Initialize( IWindsorContainer windsorContainer )       {           _windsorContainer = windsorContainer;       }        public static T Of<T>()       {           return _windsorContainer.Resolve<T>();       }   }   

I am trying to build the FluentValidation factory as is explained at http://www.jeremyskinner.co.uk/2010/02/22/using-fluentvalidation-with-an-ioc-container

The article uses StructureMap, but I thought I could adapt it to Castle Windsor like this:

public class CastleWindsorValidatorFactory : ValidatorFactoryBase {      public override IValidator CreateInstance( Type validatorType)     {         return ResolveType.Of<validatorType>();     } } 

Notice, I'm just trying to call into my wrapper so that Windsor can resolve the type reference.

The problem is that this doesn't compile. I get 'The type or namespace name 'validatorType' could not be found (are you missing a using directive or an assembly reference?)'

How can I make this work?


Custom 400 redirect based on MVC Controller

1:

Using ASP.NET MVC 2 to display joined record
Add this method to your ResolveType class:. To achieve basic code coverage what tests should I run against an ASP.NET MVC Controller?
public static object Of(Type type) {   return _windsorContainer.Resolve(type); } 
Then in your CastleWindsorValidatorFactory:. Using ASP.Net MVC Data Annotation outside of MVC
public class CastleWindsorValidatorFactory : ValidatorFactoryBase {     public override IValidator CreateInstance(Type validatorType) {         return ResolveType.Of(validatorType) as IValidator;     } } 
twitter like alert jquery in asp.net mvc

90 out of 100 based on 55 user ratings 450 reviews

#