title: How to properly configure NHibernate event listeners
body: <p>I'm trying to use an event listener for the first time.  All samples I've seen show how easy it is to configure, but for some reason I'm having trouble - it doesn't seem to be called.  I suspect I'm missing something obvious.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>&lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
      &lt;session-factory name="TerraCognita.LoanExpress"&gt;
          &lt;!-- other stuff... --&gt;
          &lt;listener type="delete" class="Test.TestDeleteListener, MyDllName" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>as well as:</p>
  
  <pre><code>&lt;hibernate-configuration   xmlns="urn:nhibernate-configuration-2.2"&gt;
      &lt;session-factory name="TerraCognita.LoanExpress"&gt;
          &lt;!-- other stuff... --&gt;
          &lt;event type="delete"&gt;
              &lt;listener class="Test.TestDeleteListener, MyDllName" /&gt;
          &lt;/event&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>When configuration is loaded and the session factory is built:</p>
  
  <pre><code>var cfg = new NHibernate.Cfg.Configuration();
  cfg.AddAssembly("MyDllName");
  sessionFactory = cfg.BuildSessionFactory();
  </code></pre>
  
  <p>After instantiation, cfg.EventListeners.DeleteEventListeners has a single entry, of type DefaultDeleteEventListener (as I'd expect).  However, after cfg.AddAssembly is called, <i>this is still the case</i> - but given the configuration, I would expect that the DeleteEventListener should actually be of type TestDeleteListener.</p>
  
  <p>In my unit test, the only way I can get my event listener working is by manually adding it to the session info:</p>
  
  <pre><code>var sess = GetSession();
  sess.GetSessionImplementation().Listeners.DeleteEventListeners = 
      new NHibernate.Event.IDeleteEventListener[] { new TestDeleteListener() };
  </code></pre>
  
  <p>I know this shouldn't be required, and I should be able to configure it properly.  Can anyone shine a light on what I'm doing wrong here?</p>