in

CodePrairie .NET

South Dakota .NET User Group

chrisortman

Hooking into new Nhibernate features from Castle ActiveRecord

NHibernate has a lot of great new features. One of which is support for events.

However, if you are using Castle ActiveRecord you can't specify these things in the configuration like you normally could and must instead roll up your sleeves and do it programatically.

There are 2 hooks in ActiveRecord that we can use to accomplish our goal.

The first is SessionFactoryHolderCreated which will notify you that the thing that holds the NHibernate ISessionFactory is ready. The next is RootTypeRegistered which happens after the active record configuration has been turned into NHibernate configuration.

Here is a simple example

IConfigurationSource source = ConfigurationSettings.GetConfig("activerecord") as IConfigurationSource;

ActiveRecordStarter.SessionFactoryHolderCreated += (holder) => {

  holder.OnRootTypeRegistered += (sender, rootType) => {

    var mholder = sender as ISessionFactoryHolder;

    var nhConfig = mholder.GetConfiguration( rootType);

    nhConfig.EventListeners. PreUpdateEventListeners =

    new NHibernate.Event. IPreUpdateEventListener[] {new MyEventListener()};

  };

};

Technorati Tags: , ,

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
Powered by Community Server (Commercial Edition), by Telligent Systems