使用FluentValidation在MVC2温莎城堡和Entity Framework 4.0(POCO) [英] Using FluentValidation with Castle Windsor and Entity Framework 4.0 (POCO) in MVC2

查看:213
本文介绍了使用FluentValidation在MVC2温莎城堡和Entity Framework 4.0(POCO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是一个很简单的问题,但希望有人通过它运行。

This isn't a very simple question, but hopefully someone has run across it.

我试图让下面的东西一起工作:

I am trying to get the following things working together:


  1. MVC2

  2. FluentValidation

  3. 实体框架4.0(POCO)

  4. 温莎城堡

我已经pretty多得的一切工作。我有温莎城堡和实施与控制器的工作由是MVCContrib的一部分WindsorControllerFactory被服务的。我也有城堡提供了FluentValidation验证正如本文所描述:的http://www.jeremyskinner.co.uk/2010/02/22/using-fluentvalidation-with-an-ioc-container/

I've pretty much gotten everything working. I have Castle Windsor implemented and working with the Controllers being served up by the WindsorControllerFactory that is part of MVCContrib. I also have Castle serving up the FluentValidation validators as is described by this article: http://www.jeremyskinner.co.uk/2010/02/22/using-fluentvalidation-with-an-ioc-container/

我的问题进来时,我尝试使用Html.EditorForModel或EditorFor在视图上。当我尝试这样做,我得到这个错误信息:

My problem comes in when I try to use Html.EditorForModel or EditorFor on a view. When I try to do that I get this error message:

支持服务的成分,不FluentValidation.IValidator`1[[System.Data.Entity.DynamicProxies.State_71C51A42554BA6C3CF05105DA05435AD209602C217FC4C34CA52ACEA2B06B99B, EntityFrameworkDynamicProxies-BrindleyInsurance.BusinessObjects,版本= 1.0.0.0,文化=中立,公钥=空]发现

No component for supporting the service FluentValidation.IValidator`1[[System.Data.Entity.DynamicProxies.State_71C51A42554BA6C3CF05105DA05435AD209602C217FC4C34CA52ACEA2B06B99B, EntityFrameworkDynamicProxies-BrindleyInsurance.BusinessObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] was found

这是由于使用的实体框架4.0的POCO产生。在运行时,生成的类获得包裹着一个动态代理,以便跟踪和懒加载可能发生。显然,使用EditorForModel或EditorFor时,它会尝试让温莎创建动态代理类型,而不是底层的真正类型的验证。

This is due to using the POCO generation on Entity Framework 4.0. At runtime, the generated classes get wrapped with a Dynamic Proxy so tracking and lazy loading can happen. Apparently, when using EditorForModel or EditorFor, it tries to ask Windsor to create a validator for the dynamic proxy type instead of the underlying real type.

有谁知道我能做些什么来解决这个问题呢?

Does anyone know what I can do to solve this issue?

推荐答案

我建议你编写自定义FluentValidatorFactory,将返回正确的验证器类类代理。

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

这篇关于使用FluentValidation在MVC2温莎城堡和Entity Framework 4.0(POCO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆