Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add event listener via Fluent NHibernate?

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?

like image 462
AwkwardCoder Avatar asked Sep 16 '09 15:09

AwkwardCoder


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.


1 Answers

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):

var config = new Configuration ();
config.AppendListeners (ListenerType.PreUpdate, new [] { new AuditEventListener () });

etc.

like image 56
Matt Enright Avatar answered Sep 19 '22 14:09

Matt Enright