views:

381

answers:

1

How can I setup NHibernate Validator with Spring.net as IoC?

I am already using Spring.net integration with NHibernate and can't get AutoRegisterListeners to work.

What I need is to setup NHV to validate entities automatically upon Update/Save instead of having to call Validate method every time and use Spring.net with ISharedEngineProvider to make sure optimal performance.

+2  A: 

After looking around a lot I found this one: http://forum.springframework.net/showthread.php?t=5286

I'm repeating it here for others to find it easier that I did!:

<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate20">

    <!-- the usual properties ... -->

    <!-- event listeners -->
<property name="EventListeners">
      <dictionary>
        <entry key="PreUpdate">
          <object type="NHibernate.Validator.Event.ValidatePreUpdateEventListener, NHibernate.Validator" />
        </entry>
        <entry key="PreInsert">
          <object type="NHibernate.Validator.Event.ValidatePreInsertEventListener, NHibernate.Validator" />
        </entry>
      </dictionary>
    </property>  </object>
Khash