<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Tags/ISession NHibernate EndRequest HttpApplication on Emad Alashi</title>
    <link>https://emadashi.com/tags/isession-nhibernate-endrequest-httpapplication/</link>
    <description>Recent content in Tags/ISession NHibernate EndRequest HttpApplication on Emad Alashi</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 14 Dec 2008 20:44:37 +0000</lastBuildDate>
    <atom:link href="https://emadashi.com/tags/isession-nhibernate-endrequest-httpapplication/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>HttpApplication EndRequest Event Invoked Many Times In Single Request?</title>
      <link>https://emadashi.com/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/</link>
      <pubDate>Sun, 14 Dec 2008 20:44:37 +0000</pubDate>
      <guid>https://emadashi.com/2008/12/httpapplication-endrequest-event-invoked-many-times-in-single-request/</guid>
      <description>&lt;p&gt;The other day I was putting the last touch of a temporary way to manage the NHibernate session (ISession) in &lt;a href=&#34;http://www.codeplex.com/bunian&#34;&gt;Bunian&lt;/a&gt;. So part of the task was to bind a method to the HttpApplication EndRequest event (in the Global.asax.cs file) like the following:&lt;/p&gt;
&lt;div style=&#34;font-size:12pt;background:#f2ebe3;color:black;font-family:courier new;&#34;&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    &lt;span style=&#34;color:blue;&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:blue;&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:blue;&#34;&gt;void&lt;/span&gt; Init()
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    {
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
           &lt;span style=&#34;color:blue;&#34;&gt;this&lt;/span&gt;.EndRequest += WorkContext.&lt;span style=&#34;color:#2b91af;&#34;&gt;NHibernateSessionManager&lt;/span&gt;.Instance.HttpRequestEnded;
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    }
  &lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;By doing this, at the end of each page request the &lt;strong&gt;NHibernateSessionManager.Instance.HttpRequestEnded()&lt;/strong&gt; will be called and I can clean the session then. But to my surprise this method was called at least 10 times!! So I thought maybe the &lt;strong&gt;Global.Init()&lt;/strong&gt; method is called many times for some reason and I ended up binding the same method to the EndRequest event many times, so I set a breakpoint at the Global.Init() method and…it&amp;rsquo;s called one time only.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
