.Net Software Development Blog
# Tuesday, June 02, 2009
IPreUpdateEventListener Registration

Ayende has a great blog post about using IPreUpdateEventListeners. I couldn’t get the event to fire for some reason. I tried registering the events in the config file like this:

            <event>
                <listener class="MyNamespace.AuditEventListener, MyAssembly"/>
            </event>
            <event>
                <listener class=”MyNamespace.AuditEventListener, MyAssembly"/>
           </event>

For some reason the events were not firing. The only thing I could figure was something in my namespace or assembly was incorrect but I checked everything multiple times and could never get it to work. Eventually I had to pass the registration through to the config file while setting up my SessionFactory this:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.EventListeners.PreUpdateEventListeners = 
    new IPreUpdateEventListener[] {new AuditEventListener()};
cfg.EventListeners.PreInsertEventListeners =
    new IPreInsertEventListener[] { new AuditEventListener() };
_sessionFactory = cfg.BuildSessionFactory();

I’m still not sure what the problem was, still betting on a namespace or assembly naming issue. I’ll add it to my list of things to look at when I get some time.
Tuesday, June 02, 2009 4:04:35 AM (Central Daylight Time, UTC-05:00)  #    Comments [0]