I want to add an event listener (IPreUpdateEventListener
) to add NHibernate but I can't seem to find an example when using a fluent configuration.
I want to be able to add the listener when I create the session factory, e.g. when the following code is execute.
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString).ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<IEntity>())
.BuildSessionFactory();
Anyone know how to do this?
Late answer, found your question when I was trying to do the same. Found a solution that should work:
So, late response, but for the sake of posterity, to add listeners without removing existing registration listeners (like the earlier answer from Bengt Be will do):
etc.
Resurrecting the dead here but this:
Should be:
I believe the 'SetListener' method (described in another answer) would also remove all previous listeners.
If you are into something a little more dynamic, you could do this:
And then call something like this:
This allows for cleaner code while you are looking at the Fluent configuration. It also allows you to easily register a single type to multiple listener types.
As for removing the default listeners, I wouldn't remove them unless I have a listener that inherits from the default listener implementation and calls base.METHODNAME on the overridden methods or replicates the same behavior as that of the default listeners.