I'm trying to add an implementation of IPostLoadEventListener to my NHibernate configuration using FluentNHibernate. I can do so as illustrated here:
http://stackoverflow.com/questions/1433638/how-to-add-event-listener-via-fluent-nhibernate
However, creating a new array to replace the old one completely discards any existing event listeners. I can get around that like so:
return Fluently.Configure()
.Database(config)
.Mappings(m => m.AutoMappings.Add(mappings))
.ExposeConfiguration(cfg =>
{
cfg.EventListeners.PostLoadEventListeners =
new IPostLoadEventListener[] {
new UtcDateEventListener(),
new DefaultPostLoadEventListener() // <<< this one is the default
};
cfg.EventListeners.SaveOrUpdateEventListeners =
new ISaveOrUpdateEventListener[] {
new UtcDateEventListener(),
new DefaultSaveOrUpdateEventListener() // <<< this one is the default
};
})
.BuildConfiguration()
.BuildSessionFactory();
But I only know about the default event listeners by stepping through the code to determine what I was overwriting. I'd like to add my event listener without overwriting any existing event listeners, but doing so like I've shown above seems very smelly, to me. The existing event listeners are exposed as an array (rather than a collection or a list, which would make more sense). Is there a cleaner way to handle this?