﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Jimmy Zimms commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>I'm not a fan of singletons (well not container managed) and especially the infamous HttpContext.Current property but this is one place where when it does make sense to go down that route to leverage MSR Moles for testing purposes. Again, I usually try to design around that but there's times when it's just the best approach when complexity vs "purity" is balanced out in a solution.
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment20</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment20</guid><pubDate>Thu, 07 Apr 2011 18:36:30 GMT</pubDate></item><item><title>Scooletz commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>A IoC container is the way to go. That's all about this code
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment19</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment19</guid><pubDate>Thu, 07 Apr 2011 10:03:42 GMT</pubDate></item><item><title>Rob Kent commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Thanks, I just found your blog entry on the cost of opening a Session: 
[ayende.com/.../...e-cost-of-opening-a-session.aspx](http://ayende.com/Blog/archive/2009/08/16/what-is-the-cost-of-opening-a-session.aspx)</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment18</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment18</guid><pubDate>Thu, 07 Apr 2011 09:53:03 GMT</pubDate></item><item><title>Ayende Rahien commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>There is no cost for opening a new NH session.
  
And yes, you always want a session available, see my previous posts about why I dislike the repo pattern
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment17</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment17</guid><pubDate>Thu, 07 Apr 2011 09:34:50 GMT</pubDate></item><item><title>Rob Kent commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>It's nice and simple. I have two comments though. 
  
  
In MVC 2, at least, we get a BeginRequest for every static resource, including images, Javascript, and CSS files. Maybe there is little overhead to opening an NH Session and I could be being excessively defensive, but I wrote a routine to check that we were processing an ASP request before I did anything like authenticating the user or opening an ISession.
  
  
Secondly, do you always need an ISession? I prefer to use a simple 'repository' that opens the session on demand and uses NH CurrentSessionContext.
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment16</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment16</guid><pubDate>Thu, 07 Apr 2011 09:31:24 GMT</pubDate></item><item><title>Ayende Rahien commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Adam,
  
In general, yes, a single session for the entire request is the way to go.
  
As for replacing this. Please wait, we have much better coming up
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment15</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment15</guid><pubDate>Thu, 07 Apr 2011 08:30:47 GMT</pubDate></item><item><title>Adam B commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>I like it, but I was using the castle nhibernate facility and replacting that with this broke my app. Some requests used multiple sessions if certain filters were being invoked. Do you think that's actually a problem with *my* code? Should *all* requests come under one session?
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment14</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment14</guid><pubDate>Thu, 07 Apr 2011 07:52:49 GMT</pubDate></item><item><title>Tyler Burd commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Generally I prefer taking a direct dependency on ISession rather than using some sort of "CurrentSession" accessor.  Easy enough to set up ISession as a service in Windsor, at least, with a PerWebRequest scope.
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment13</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment13</guid><pubDate>Thu, 07 Apr 2011 05:49:24 GMT</pubDate></item><item><title>joe commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>There might be some overhead if running that in Cassini, which runs every request (including static content) through asp.net. 
  
  
I expect to see a lazy loaded UnitOfWork in the next post :)
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment12</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment12</guid><pubDate>Wed, 06 Apr 2011 21:31:14 GMT</pubDate></item><item><title>Josh (@rebootd) commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Curious to see the upcoming series. I use code a lot like this in my MS MVC3 app(s).
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment11</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment11</guid><pubDate>Wed, 06 Apr 2011 16:38:08 GMT</pubDate></item><item><title>alexander commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>You are crazy idiot. This code is holy shit!
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment10</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment10</guid><pubDate>Wed, 06 Apr 2011 16:04:50 GMT</pubDate></item><item><title>jhigh2000 commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>As you say, It's really not bad at all, but you can definitely tuck some of the noise away by using a global action filter and your own base controller to manage your ISession.
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment9</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment9</guid><pubDate>Wed, 06 Apr 2011 15:30:34 GMT</pubDate></item><item><title>Ayende Rahien commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Ryan,
  
Relevance for the post? 
  
There are ways to handle that, based on however you determine which tenant you are in, but it isn't relevant for this scenario
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment8</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment8</guid><pubDate>Wed, 06 Apr 2011 14:46:42 GMT</pubDate></item><item><title>Tim commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Can't wait for the rest of this series.
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment7</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment7</guid><pubDate>Wed, 06 Apr 2011 14:46:16 GMT</pubDate></item><item><title>Ryan McDonald commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>In the case of a RavenDB session object, how could you provide a database name to the call to OpenSessoin() in BeginRequest ?
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment6</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment6</guid><pubDate>Wed, 06 Apr 2011 14:43:50 GMT</pubDate></item><item><title>Glenn Morton commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Is there much of an overhead opening a session for every request that hits the application - feels a little excessive. Would it not be better to place an filter attribute on the controller to restrict the creation of sessions to only requests that require it?
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment5</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment5</guid><pubDate>Wed, 06 Apr 2011 14:36:27 GMT</pubDate></item><item><title>Scott White commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>In other words Open Session in View (OSIV).  The next step I assume will be to configure NHibernate to use web session scope?
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment4</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment4</guid><pubDate>Wed, 06 Apr 2011 14:02:11 GMT</pubDate></item><item><title>Chris Hynes commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>I'm very interested to see what you recommend. With your recent rantings on the demise of the Repository pattern, I looked at your code samples. The only things I could find were client projects, which require rather different architectures than web. MVC3 + NHibernate3 is an excellent combo.
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment3</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment3</guid><pubDate>Wed, 06 Apr 2011 13:55:43 GMT</pubDate></item><item><title>Ayende Rahien commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Wait for the whole series
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment2</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment2</guid><pubDate>Wed, 06 Apr 2011 10:48:28 GMT</pubDate></item><item><title>Robert M&amp;#252;hsig commented on Refactoring toward frictionless &amp; odorless code: The baseline</title><description>Is this code still unit-testable? HttpContext and the static seems to be a problem if you try to write a test for the controller action. How do you solve this?
  
  
Thanks,
  
Robert
</description><link>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment1</link><guid>http://ayende.com/4803/refactoring-toward-frictionless-odorless-code-the-baseline#comment1</guid><pubDate>Wed, 06 Apr 2011 10:26:21 GMT</pubDate></item></channel></rss>