asp.net-mvc - 在 MVC2 中使用 FluentValidation 与 CaSTLe Windsor 和 Entity Framework 4.0 (POCO)

标签 asp.net-mvc entity-framework castle-windsor poco fluentvalidation

这不是一个非常简单的问题,但希望有人遇到过。

我正在努力让以下事情协同工作:

  1. MVC2
  2. 流利验证
  3. Entity Framework 4.0 (POCO)
  4. 温莎城堡

我已经把一切都搞定了。我已经实现了 CaSTLe Windsor,并使用由 WindsorControllerFactory(MVCContrib 的一部分)提供的 Controller 进行工作。我还让 CaSTLe 提供 FluentValidation 验证器,如本文所述:http://www.jeremyskinner.co.uk/2010/02/22/using-fluentvalidation-with-an-ioc-container/

当我尝试在 View 上使用 Html.EditorForModel 或 EditorFor 时,我的问题出现了。当我尝试这样做时,我收到此错误消息:

没有支持服务 FluentValidation.IValidator`1[[System.Data.Entity.DynamicProxies.State_71C51A42554BA6C3CF05105DA05435AD209602C217FC4C34CA52ACEA2B06B99B,EntityFrameworkDynamicProxies-BrindleyInsurance.BusinessObjects,版本 = 1.0.0 的组件。 0、Culture=neutral、PublicKeyToken=null]] 已找到

这是由于在 Entity Framework 4.0 上使用 POCO 生成造成的。在运行时,生成的类被动态代理包装,因此可以发生跟踪和延迟加载。显然,当使用 EditorForModel 或 EditorFor 时,它会尝试要求 Windsor 为动态代理类型而不是底层真实类型创建验证器。

有人知道我可以做些什么来解决这个问题吗?

最佳答案

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

关于asp.net-mvc - 在 MVC2 中使用 FluentValidation 与 CaSTLe Windsor 和 Entity Framework 4.0 (POCO),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2878117/

相关文章:

c# - 在不创建实现的情况下实现接口(interface)(动态代理?)

caSTLe-windsor - TypedFactoryFacility : Passing null argument

c# - 使用 CaSTLe 容器中的已注册组件为另一个组件提供依赖项

c# - LINQ 匿名类型没有给出我需要的列表

string - Entity Framework 和 Oracle : Cannot Insert VARCHAR2 > 1, 999 个字符

c# - 错误消息 : "Only primitive types or enumeration types are supported in this context."

wcf - 具有共享对象的 Entity Framework Attach() 对象树

c# - 将 css 类添加到 razor 元素

c# - 在 Asp.Net MVC 5 中使用 Entity Framework 6 代码优先方法调用存储过程

asp.net-mvc - Asp.net Mvc OutputCache 属性和滑动过期