<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Abstracting Request State</title>
	<atom:link href="http://davybrion.com/blog/2009/01/abstracting-request-state/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2009/01/abstracting-request-state/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Tue, 16 Mar 2010 21:33:15 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-32029</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 15 Mar 2010 08:03:58 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-32029</guid>
		<description>@Kurt

the ActiveSessionManager class (found here: http://davybrion.com/blog/2009/12/using-nhibernate-in-your-service-layer/) uses the RequestState to store and retrieve the NHibernate ISession instance for the current request.

You create the ISession instance at the beginning of the request (in my case, through the construction of my UnitOfWork), and you get rid of it at the end of the request (by disposing my UnitOfWork, which in turn instructs the ActiveSessionManager to remove the current ISession from the RequestState)</description>
		<content:encoded><![CDATA[<p>@Kurt</p>
<p>the ActiveSessionManager class (found here: <a href="http://davybrion.com/blog/2009/12/using-nhibernate-in-your-service-layer/)" rel="nofollow">http://davybrion.com/blog/2009/12/using-nhibernate-in-your-service-layer/)</a> uses the RequestState to store and retrieve the NHibernate ISession instance for the current request.</p>
<p>You create the ISession instance at the beginning of the request (in my case, through the construction of my UnitOfWork), and you get rid of it at the end of the request (by disposing my UnitOfWork, which in turn instructs the ActiveSessionManager to remove the current ISession from the RequestState)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kurt schroeder</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-31927</link>
		<dc:creator>kurt schroeder</dc:creator>
		<pubDate>Sun, 14 Mar 2010 15:41:46 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-31927</guid>
		<description>without needing to be said, &quot;Yes I am still playing catchup on many concepts&quot;</description>
		<content:encoded><![CDATA[<p>without needing to be said, &#8220;Yes I am still playing catchup on many concepts&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kurt schroeder</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-31679</link>
		<dc:creator>kurt schroeder</dc:creator>
		<pubDate>Fri, 12 Mar 2010 18:56:09 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-31679</guid>
		<description>In the case of storing/retreaving an NHibernate session i&#039;m not sure where and how it is supposed to be stored. I have a class called RequestState, but have not progressed past this point. This is actually in reference to the yup above. I agree with Chuck, &quot;Good stuff. Learning lots&quot;. After spending a fair amount of time on this i have learned a lot even today. That said, it&#039;s time to ask for a little help How does the session state for NHibernate get stored.

Appreciated.
KES</description>
		<content:encoded><![CDATA[<p>In the case of storing/retreaving an NHibernate session i&#8217;m not sure where and how it is supposed to be stored. I have a class called RequestState, but have not progressed past this point. This is actually in reference to the yup above. I agree with Chuck, &#8220;Good stuff. Learning lots&#8221;. After spending a fair amount of time on this i have learned a lot even today. That said, it&#8217;s time to ask for a little help How does the session state for NHibernate get stored.</p>
<p>Appreciated.<br />
KES</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-10040</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Tue, 17 Mar 2009 22:07:55 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-10040</guid>
		<description>&quot;Would the IRequestState be used in the ActiveSessionManager class to replace the field called “current?” &quot;

yup :)

and yeah, you could definitely use a Dictionary-based TestRequestState implementation for your tests</description>
		<content:encoded><![CDATA[<p>&#8220;Would the IRequestState be used in the ActiveSessionManager class to replace the field called “current?” &#8221;</p>
<p>yup <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>and yeah, you could definitely use a Dictionary-based TestRequestState implementation for your tests</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-10039</link>
		<dc:creator>Chuck</dc:creator>
		<pubDate>Tue, 17 Mar 2009 22:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-10039</guid>
		<description>Davy - 

Just catching up on your post. Does this tie into your unit of work article? Would the IRequestState be used in the ActiveSessionManager class to replace the field called &quot;current?&quot; 

I was thinking that for testing, I would have an Implementation of IRequestState that did not depend on HttpContext. In order to keep with the IRequestState interface, it seems like I would need to use something like a Dictionary. Does that sound right?

Good stuff. Learning lots.

C</description>
		<content:encoded><![CDATA[<p>Davy &#8211; </p>
<p>Just catching up on your post. Does this tie into your unit of work article? Would the IRequestState be used in the ActiveSessionManager class to replace the field called &#8220;current?&#8221; </p>
<p>I was thinking that for testing, I would have an Implementation of IRequestState that did not depend on HttpContext. In order to keep with the IRequestState interface, it seems like I would need to use something like a Dictionary. Does that sound right?</p>
<p>Good stuff. Learning lots.</p>
<p>C</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop &#8211; January 17, 2009 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7880</link>
		<dc:creator>Dew Drop &#8211; January 17, 2009 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Mon, 19 Jan 2009 12:26:04 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7880</guid>
		<description>[...] Abstracting Request State (Davy Brion) [...]</description>
		<content:encoded><![CDATA[<p>[...] Abstracting Request State (Davy Brion) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7878</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 19 Jan 2009 11:35:42 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7878</guid>
		<description>ah ok, i also thought it worked but i know that Ayende recently did some work on TransactionScope in the trunk so i wasn&#039;t sure... i think those changes were mostly MSDTC related though</description>
		<content:encoded><![CDATA[<p>ah ok, i also thought it worked but i know that Ayende recently did some work on TransactionScope in the trunk so i wasn&#8217;t sure&#8230; i think those changes were mostly MSDTC related though</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Degosserie</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7876</link>
		<dc:creator>Steve Degosserie</dc:creator>
		<pubDate>Mon, 19 Jan 2009 11:33:57 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7876</guid>
		<description>It works, I&#039;ve tested in the past (if my memory is not failing me lol) ... not sure if ISession is fully memory-transactional yet though (but that is rarely usefull anyway, you&#039;re usually supposed to throw away your ISession instance in case of a Tx Rollback).</description>
		<content:encoded><![CDATA[<p>It works, I&#8217;ve tested in the past (if my memory is not failing me lol) &#8230; not sure if ISession is fully memory-transactional yet though (but that is rarely usefull anyway, you&#8217;re usually supposed to throw away your ISession instance in case of a Tx Rollback).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7875</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 19 Jan 2009 11:26:44 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7875</guid>
		<description>yes, i&#039;m talking about a WCF service layer

i guess i could use WCF&#039;s transactional options, but so far this custom UoW approach is working pretty good so i&#039;m not just going to change it.  

btw, NHibernate does have support for TransactionScope (although that might just be in the current trunk, not sure about that) so what you&#039;re doing should work as well</description>
		<content:encoded><![CDATA[<p>yes, i&#8217;m talking about a WCF service layer</p>
<p>i guess i could use WCF&#8217;s transactional options, but so far this custom UoW approach is working pretty good so i&#8217;m not just going to change it.  </p>
<p>btw, NHibernate does have support for TransactionScope (although that might just be in the current trunk, not sure about that) so what you&#8217;re doing should work as well</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve Degosserie</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7874</link>
		<dc:creator>Steve Degosserie</dc:creator>
		<pubDate>Mon, 19 Jan 2009 11:20:26 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7874</guid>
		<description>Hello Davy,

So your custom UoW starts NH transaction when you enter your service layer ... when you say &#039;service layer&#039;, are you talking about your WCF services, or another logical service layer below your WCF services ? if WCF service layer, why not use the transactional options of WCF over your custom implementation?

What I&#039;m usually doing is have an interceptor on my Business Layer to start transactions that nest with the ones from the (WCF) service layer (if any) ... that&#039;s where System.Transactions TransactionScope come in handy ... but that implies that the underlying ORM used must support TransactionScope.</description>
		<content:encoded><![CDATA[<p>Hello Davy,</p>
<p>So your custom UoW starts NH transaction when you enter your service layer &#8230; when you say &#8217;service layer&#8217;, are you talking about your WCF services, or another logical service layer below your WCF services ? if WCF service layer, why not use the transactional options of WCF over your custom implementation?</p>
<p>What I&#8217;m usually doing is have an interceptor on my Business Layer to start transactions that nest with the ones from the (WCF) service layer (if any) &#8230; that&#8217;s where System.Transactions TransactionScope come in handy &#8230; but that implies that the underlying ORM used must support TransactionScope.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7871</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 19 Jan 2009 09:50:05 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7871</guid>
		<description>the UoW implementation is probably very similar to other ones

i didn&#039;t really say that TransactionScope isn&#039;t useful, just that i don&#039;t use it :)

the only reason why i don&#039;t use it is because i just stick with the transactions that NHibernate provides me with, and that works well for me</description>
		<content:encoded><![CDATA[<p>the UoW implementation is probably very similar to other ones</p>
<p>i didn&#8217;t really say that TransactionScope isn&#8217;t useful, just that i don&#8217;t use it <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>the only reason why i don&#8217;t use it is because i just stick with the transactions that NHibernate provides me with, and that works well for me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Pook</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7870</link>
		<dc:creator>Andy Pook</dc:creator>
		<pubDate>Mon, 19 Jan 2009 09:14:12 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7870</guid>
		<description>And that uses the same technique to ensure you always get the correct ambient transaction?
I assume that your custom UoW is similar to others out there? Giving nestable transaction scope, rollback, commit etc.
You intimate that TransactionScope isn&#039;t useful. What, essentially, do you see as the benefit of a custom UoW over TransactionScope?</description>
		<content:encoded><![CDATA[<p>And that uses the same technique to ensure you always get the correct ambient transaction?<br />
I assume that your custom UoW is similar to others out there? Giving nestable transaction scope, rollback, commit etc.<br />
You intimate that TransactionScope isn&#8217;t useful. What, essentially, do you see as the benefit of a custom UoW over TransactionScope?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7828</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Sun, 18 Jan 2009 17:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7828</guid>
		<description>i indeed use NHibernate

I basically start a transaction whenever i enter my service layer, and everything that happens from then on is managed by the parent transaction.  I can call any piece of code knowing that everything that gets executed can be committed or rolled back by the parent transaction.  I use a custom Unit Of Work implementation for this.</description>
		<content:encoded><![CDATA[<p>i indeed use NHibernate</p>
<p>I basically start a transaction whenever i enter my service layer, and everything that happens from then on is managed by the parent transaction.  I can call any piece of code knowing that everything that gets executed can be committed or rolled back by the parent transaction.  I use a custom Unit Of Work implementation for this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Pook</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7826</link>
		<dc:creator>Andy Pook</dc:creator>
		<pubDate>Sun, 18 Jan 2009 17:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7826</guid>
		<description>violated: Sure, as far as the clr runtime spec is concerned. But then ThreadStatic is, as you&#039;ve discovered, pretty broken in asp anyway. (unless you really know where asp async method may not complete synchronously).

TransactionScope: I assume from your comment that you use some ORM (NHibernate etc). Have you no need for ambient transaction/session to be able to compose various actions coded in separate methods/classes?</description>
		<content:encoded><![CDATA[<p>violated: Sure, as far as the clr runtime spec is concerned. But then ThreadStatic is, as you&#8217;ve discovered, pretty broken in asp anyway. (unless you really know where asp async method may not complete synchronously).</p>
<p>TransactionScope: I assume from your comment that you use some ORM (NHibernate etc). Have you no need for ambient transaction/session to be able to compose various actions coded in separate methods/classes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7818</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Sun, 18 Jan 2009 11:29:54 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7818</guid>
		<description>if they were to migrate the ThreadStatic values for us, it would appear to work correctly but it would be a pretty ugly hack where the whole concept of ThreadStatic is pretty much violated :)

dunno about TransactionScope though... haven&#039;t used that in a while :)</description>
		<content:encoded><![CDATA[<p>if they were to migrate the ThreadStatic values for us, it would appear to work correctly but it would be a pretty ugly hack where the whole concept of ThreadStatic is pretty much violated <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>dunno about TransactionScope though&#8230; haven&#8217;t used that in a while <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Pook</title>
		<link>http://davybrion.com/blog/2009/01/abstracting-request-state/comment-page-1/#comment-7817</link>
		<dc:creator>Andy Pook</dc:creator>
		<pubDate>Sun, 18 Jan 2009 11:25:36 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=857#comment-7817</guid>
		<description>This comes up every so often (ASP.Net thread agility).
Ayende has a class (as you&#039;d expect!!) called LocalData in Rhino.Commons that does something similar (but doesn&#039;t cover the WCF scenario). I and many others have our own various solutions.

There are 2 questions that I always have with this:
 1. if this is such a problem in ASP. Why doesn&#039;t the ASP runtime do that magic to migrate the thread statics for us? It must do something similar to make HttpContext.Current migrate.
 2. How does TransactionScope work? Internally it seems to use a ThreadStatic in a helper class called ContextData.

The answer to 1. is... That&#039;s just the way it is, we&#039;d best just get on with it!
The answer to 2. is unclear. Does this also fail in the high load ASP scenario or is there some other magic I&#039;m not seeing that we can borrow instead of many different wheels?

--Andy</description>
		<content:encoded><![CDATA[<p>This comes up every so often (ASP.Net thread agility).<br />
Ayende has a class (as you&#8217;d expect!!) called LocalData in Rhino.Commons that does something similar (but doesn&#8217;t cover the WCF scenario). I and many others have our own various solutions.</p>
<p>There are 2 questions that I always have with this:<br />
 1. if this is such a problem in ASP. Why doesn&#8217;t the ASP runtime do that magic to migrate the thread statics for us? It must do something similar to make HttpContext.Current migrate.<br />
 2. How does TransactionScope work? Internally it seems to use a ThreadStatic in a helper class called ContextData.</p>
<p>The answer to 1. is&#8230; That&#8217;s just the way it is, we&#8217;d best just get on with it!<br />
The answer to 2. is unclear. Does this also fail in the high load ASP scenario or is there some other magic I&#8217;m not seeing that we can borrow instead of many different wheels?</p>
<p>&#8211;Andy</p>
]]></content:encoded>
	</item>
</channel>
</rss>
