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

Posted by Brian McCord on Stack Overflow See other posts from Stack Overflow or by Brian McCord
Published on 2010-05-20T21:50:16Z Indexed on 2010/05/20 21:50 UTC
Read the original article Hit count: 737

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. Entity Framework 4.0 (POCO)
  4. Castle Windsor

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/

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:

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

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about fluentvalidation