Using FluentValidation with Castle Windsor and Entity Framework 4.0 (POCO) in MVC2

喜夏-厌秋 提交于 2019-12-06 05:13:20

I suggest you to write custom FluentValidatorFactory that will return correct validator class for class-proxy.

This the CreateInstance method of my ValidatorFactory. If you see a better way, please comment.

    public override IValidator CreateInstance( Type validatorType)
    {
        if( validatorType.GetGenericArguments()[0].Namespace.Contains( "DynamicProxies" ) )
        {
            validatorType = Type.GetType( String.Format( "{0}.{1}[[{2}]], {3}", validatorType.Namespace, validatorType.Name, validatorType.GetGenericArguments()[0].BaseType.AssemblyQualifiedName, validatorType.Assembly.FullName ) );

        }

        return ResolveType.Of( validatorType ) as IValidator;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!