<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Agile at Work &#187; Single Responsibility Principle</title>
	<atom:link href="http://www.agileatwork.com/tag/single-responsibility-principle/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.agileatwork.com</link>
	<description>by Michael Valenty</description>
	<lastBuildDate>Sat, 10 Sep 2011 14:35:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tamarack: Chain of Responsibility Framework for .NET</title>
		<link>http://www.agileatwork.com/tamarack-chain-of-responsibility-framework-for-net/</link>
		<comments>http://www.agileatwork.com/tamarack-chain-of-responsibility-framework-for-net/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 05:39:04 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Chain of Responsibility]]></category>
		<category><![CDATA[Inversion of Control]]></category>
		<category><![CDATA[Single Responsibility Principle]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/?p=554</guid>
		<description><![CDATA[The Chain of Responsibility is a key building block of extensible software.
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. – Gang of Four

Variations of this [...]]]></description>
			<content:encoded><![CDATA[<p>The Chain of Responsibility is a key building block of extensible software.</p>
<blockquote><p>Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. – Gang of Four</p>
</blockquote>
<p>Variations of this pattern are the basis for <a href="http://www.oracle.com/technetwork/java/filters-137243.html">Servlet Filters</a>, <a href="http://learn.iis.net/page.aspx/366/developing-iis-70-modules-and-handlers-with-the-net-framework/">IIS Modules and Handlers</a> and several open source projects I’ve had the opportunity to work with including <a href="https://www.forge.funambol.org/">Sync4J</a>, <a href="http://james.apache.org/">JAMES</a>, <a href="http://logging.apache.org/log4net/">Log4Net</a>, <a href="http://unity.codeplex.com/">Unity</a> and yes, even <a href="http://www.joomla.org/">Joomla</a>. It&#8217;s an essential tool in the OO toolbox and key in transforming rigid procedural code into a composable Domain Specific Language.</p>
<p><a href="http://www.agileatwork.com/where-does-it-hurt/">I’ve blogged about this pattern before</a> so what’s new this time?</p>
<ol>
<li>The next filter in the chain is provided via a delegate parameter rather than a property </li>
<li>The project is <a href="https://github.com/mikevalenty/tamarack">hosted on github</a> </li>
<li>There is a <a href="http://nuget.org/List/Search?packageType=Packages&amp;searchCategory=All+Categories&amp;searchTerm=tamarack">NuGet package</a> for it </li>
</ol>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="pkgmgr3" border="0" alt="pkgmgr3" src="http://www.agileatwork.com/wp-content/uploads/2011/04/pkgmgr31.png" width="640" height="332" /> </p>
<h3>How does it work?</h3>
<p>It&#8217;s pretty simple, there is just one interface to implement and it looks like this:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: #2b91af">IFilter</span>&lt;T, TOut&gt;</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">    TOut Execute(T context, <span style="color: #2b91af">Func</span>&lt;T, TOut&gt; executeNext);</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>Basically, you get an input to operate on and a value to return. The <font size="2" face="Courier New">executeNext</font> parameter is a delegate for the next filter in the chain. The filters are composed together in a chain which is referred to as a <font size="2" face="Courier New">Pipeline</font> in the Tamarack framework. This structure is the essence of the Chain of Responsibility pattern and it facilitates some pretty cool things:</p>
<ul>
<li>Modify the input before the next filter gets it </li>
<li>Modify the output of the next filter before returning </li>
<li>Short circuit out of the chain by not calling the executeNext delegate </li>
</ul>
<h3>Show me examples!</h3>
<p>Consider a block of code to process a blog comment coming from a web-based rich text editor. There are probably several things you&#8217;ll want to do before letting the text into your database.</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">int</span> Submit(<span style="color: #2b91af">Post</span> post)</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">var</span> pipeline = <span style="color: blue">new</span> <span style="color: #2b91af">Pipeline</span>&lt;<span style="color: #2b91af">Post</span>, <span style="color: blue">int</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add(<span style="color: blue">new</span> <span style="color: #2b91af">CanoncalizeHtml</span>())</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add(<span style="color: blue">new</span> <span style="color: #2b91af">StripMaliciousTags</span>())</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add(<span style="color: blue">new</span> <span style="color: #2b91af">RemoveJavascript</span>())</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add(<span style="color: blue">new</span> <span style="color: #2b91af">RewriteProfanity</span>())</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add(<span style="color: blue">new</span> <span style="color: #2b91af">GuardAgainstDoublePost</span>())</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Finally(p =&gt; repository.Save(p));</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">var</span> newId = pipeline.Execute(post);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">return</span> newId;</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>What about dependency injection for complex filters? Take a look at this user login pipeline. Notice the generic syntax for adding filters by type. Those filters are built-up using the supplied implementation of <font size="2" face="Courier New">System.IServiceProvider</font>. My favorite is <font size="2" face="Courier New">UnityServiceProvider</font>.</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">bool</span> Login(<span style="color: blue">string</span> username, <span style="color: blue">string</span> password)</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">var</span> pipeline = <span style="color: blue">new</span> <span style="color: #2b91af">Pipeline</span>&lt;<span style="color: #2b91af">LoginContext</span>, <span style="color: blue">bool</span>&gt;(serviceProvider)</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">WriteLoginAttemptToAuditLog</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">LockoutOnConsecutiveFailures</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">AuthenticateAgainstLocalStore</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">AuthenticateAgainstLdap</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Finally(c =&gt; <span style="color: blue">false</span>);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">return</span> pipeline.Execute(<span style="color: blue">new</span> <span style="color: #2b91af">LoginContext</span>(username, password));</pre>
<pre style="margin: 0px">}</pre>
<pre style="margin: 0px">&#160;</pre>
</div>
<p>Here’s another place you might see the chain of responsibility pattern. Calculating the spam score of a block of text:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">double</span> CalculateSpamScore(<span style="color: blue">string</span> text)</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">var</span> pipeline = <span style="color: blue">new</span> <span style="color: #2b91af">Pipeline</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">double</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">SpamCopBlacklistFilter</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">PerspcriptionDrugFilter</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Add&lt;<span style="color: #2b91af">PornographyFilter</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Finally(score =&gt; 0);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">return</span> pipeline.Execute(text);</pre>
<pre style="margin: 0px">}</pre>
<pre style="margin: 0px">&#160;</pre>
</div>
<p>Prefer convention over configuration? Try this instead:</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">double</span> CalculateSpamScore(<span style="color: blue">string</span> text)</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">var</span> pipeline = <span style="color: blue">new</span> <span style="color: #2b91af">Pipeline</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">double</span>&gt;()</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .AddFiltersIn(<span style="color: #a31515">&quot;Tamarack.Example.Pipeline.SpamScorer.Filters&quot;</span>)</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; .Finally(score =&gt; 0);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">return</span> pipeline.Execute(text);</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>Let&#8217;s look at the <font size="2" face="Courier New">IFilter</font> interface in action. In the spam score calculator example, each filter looks for markers in the text and adds to the overall spam score by modifying the <em>result</em> of the next filter before returning.</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">PerspcriptionDrugFilter</span> : <span style="color: #2b91af">IFilter</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">double</span>&gt;</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">double</span> Execute(<span style="color: blue">string</span> text, <span style="color: #2b91af">Func</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">double</span>&gt; executeNext)</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> score = executeNext(text);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (text.Contains(<span style="color: #a31515">&quot;viagra&quot;</span>))</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; score += .25;</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> score;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>In the login example, we look for the user in our local user store and if it exists we&#8217;ll short-circuit the chain and authenticate the request. Otherwise we&#8217;ll let the request continue to the next filter which looks for the user in an LDAP repository.</p>
<div style="font-family: consolas; background: white; color: black; font-size: 10pt">
<pre style="margin: 0px"><span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">AuthenticateAgainstLocalStore</span> : <span style="color: #2b91af">IFilter</span>&lt;<span style="color: #2b91af">LoginContext</span>, <span style="color: blue">bool</span>&gt;</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">readonly</span> <span style="color: #2b91af">IUserRepository</span> repository;</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> AuthenticateAgainstLocalStore(<span style="color: #2b91af">IUserRepository</span> repository)</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">this</span>.repository = repository;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">public</span> <span style="color: blue">bool</span> Execute(<span style="color: #2b91af">LoginContext</span> context, <span style="color: #2b91af">Func</span>&lt;<span style="color: #2b91af">LoginContext</span>, <span style="color: blue">bool</span>&gt; executeNext)</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> user = repository.FindByUsername(context.Username);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">if</span> (user != <span style="color: blue">null</span>)</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> user.IsValid(context.Password);</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">return</span> executeNext(context);</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">}</pre>
</div>
<h3>Why should I use it?</h3>
<blockquote>
<p>It&#8217;s pretty much my favorite animal. It&#8217;s like a lion and a tiger mixed&#8230; bred for its skills in magic. – Napoleon Dynamite</p>
</blockquote>
<p>It’s simple and mildly opinionated in effort to guide you and your code into <a href="http://blogs.msdn.com/b/brada/archive/2003/10/02/50420.aspx">The Pit of Success</a>. It’s easy to write single responsibility classes and use inversion of control and composition and convention over configuration and lots of other goodness. Try it out. Tell a friend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/tamarack-chain-of-responsibility-framework-for-net/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Rafactoring: Introduce Parameter Object</title>
		<link>http://www.agileatwork.com/rafactoring-introduce-parameter-object/</link>
		<comments>http://www.agileatwork.com/rafactoring-introduce-parameter-object/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 23:59:06 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Introduce Parameter Object]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Single Responsibility Principle]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/?p=412</guid>
		<description><![CDATA[Take a look at this function:
public UserIndexViewModel GetIndexViewModel(int pageSize, int pageNumber) {
    var model = new UserIndexViewModel();

    var allUsers = Session.CreateCriteria&#60;User&#62;();

    model.Total = CriteriaTransformer
        .TransformToRowCount(allUsers)
        .UniqueResult&#60;int&#62;();

    model.Users = allUsers
 [...]]]></description>
			<content:encoded><![CDATA[<p>Take a look at this function:</p>
<pre class="prettyprint"><code>public UserIndexViewModel GetIndexViewModel(int pageSize, int pageNumber) {
    var model = new UserIndexViewModel();

    var allUsers = Session.CreateCriteria&lt;User&gt;();

    model.Total = CriteriaTransformer
        .TransformToRowCount(allUsers)
        .UniqueResult&lt;int&gt;();

    model.Users = allUsers
        .SetFirstResult(pageSize * (pageNumber - 1) + 1)
        .SetMaxResults(pageSize)
        .AddOrder&lt;User&gt;(u =&gt; u.LastName, Order.Asc)
        .List&lt;User&gt;();

    return model;
}</code></pre>
<p>There isn’t much going on here, but it could be better. I&#8217;m looking at the arguments <font size="2" face="Courier New">pageSize</font> and <font size="2" face="Courier New">pageNumber</font>. Notice how they both start with the prefix “page”. That’s a smell. The common prefix means the arguments are related, so let’s apply the <em>Introduce Parameter Object</em> refactoring and see what happens.</p>
<pre class="prettyprint"><code>public class Page {
    private readonly int number;
    private readonly int size;

    public Page(int number, int size) {
        this.number = number;
        this.size = size;
    }

    public int Size {
        get { return size; }
    }

    public int Number {
        get { return number; }
    }

    public int FirstResult {
        get { return size * (number - 1) + 1; }
    }
}</code></pre>
<p>What did we accomplish?</p>
<ul>
<li>Creating the parameter object gave us a place to put the logic of calculating the first result of the current page. This logic would otherwise be scattered around the application and even though it’s simple, it’s error prone.</li>
<li>The logic of calculating the first result is testable.</li>
</ul>
<pre class="prettyprint"><code>[Test]
public void Should_calculate_first_result_of_current_page() {
    Assert.That(new Page(1, 20).FirstResult, Is.EqualTo(1));
    Assert.That(new Page(2, 20).FirstResult, Is.EqualTo(21));
    Assert.That(new Page(3, 20).FirstResult, Is.EqualTo(41));
}</code></pre>
<p>It’s not rocket science, but it still deserves a test. Our other option is spinning up <a href="http://www.asp.net/Downloads/archived/cassini/">Cassini</a> and clicking around to make sure we got it right. That’s just silly. A little piece of me dies each time I press F5 to run a manual test.</p>
<p>Anyway, there is this thing that happens with single responsibility classes. Because their purpose is crisp, it draws out robustness. In this case, I&#8217;m thinking about what we should we do if we get zero or a negative value for page number. I’m a fail fast kind of guy, so I’d probably go with a guard clause.</li>
</p>
<pre class="prettyprint"><code>public Page(int number, int size) {
    GuardAgainstLessThanOne(number);
    ...
}</code></pre>
<p>But you could silently correct it if that&#8217;s how you roll:</p>
<pre class="prettyprint"><code>public int Number {
    get { return Math.Max(1, number); }
}</code></pre>
<p>The point is that this is an obvious scenario to consider when looking at such a special purpose object. All too often though, bits of logic are mixed together like 32 kindergarteners sitting next to each other on a rug during a lesson. The room is one fart or tickle away from erupting into total kaos. It&#8217;s roughly half teaching and half crowd control, only without the rubber bullets and pepper spray. Not surprisingly, overcrowded classrooms don&#8217;t work that well and over-ambitous functions don&#8217;t work that well either. Each little bit of logic needs some one on one with you. Give it a chance to be all it can be by pulling it aside and getting to know it a little better. You might be surprised.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/rafactoring-introduce-parameter-object/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Interfaces (No Excuses!)</title>
		<link>http://www.agileatwork.com/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-interfaces-no-excuses/</link>
		<comments>http://www.agileatwork.com/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-interfaces-no-excuses/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 06:24:17 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Single Responsibility Principle]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/?p=354</guid>
		<description><![CDATA[The title of this article was inspired by The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)     by Joel Spolsky
I recently saw this question on stackoverflow:
&#160;
There were good points on both sides, but the majority of responses were from closet interface haters succumbing [...]]]></description>
			<content:encoded><![CDATA[<p><font size="2">The title of this article was inspired by </font><a href="http://www.joelonsoftware.com/articles/Unicode.html"><font size="2">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</font></a>     <br /><font size="2">by Joel Spolsky</font></p>
<p>I recently saw this <a href="http://stackoverflow.com/questions/90851/is-it-just-me-or-are-interfaces-overused">question on stackoverflow</a>:</p>
<p><a href="http://stackoverflow.com/questions/90851/is-it-just-me-or-are-interfaces-overused"><img title="quest" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="122" alt="quest" src="http://www.agileatwork.com/wp-content/uploads/2010/01/quest.png" width="440" border="0" /></a>&#160;</p>
<p>There were good points on both sides, but the majority of responses were from closet interface haters succumbing to the mob effect to say &quot;me too&quot;. On the other side of the argument, many took cover behind regurgitated responses like interfaces are for mocking dependencies in unit tests and because people that write books say you should use them. So how is it that scores of professional software developers don&#8217;t understand or can&#8217;t communicate why and how to use the most fundamental of object-oriented language features? Perhaps there is a clue in the details of the original question:</p>
<blockquote><p>Is there some hidden benefit of using an interface when you have 1 version of a class and no immediate need to create an interface?</p></blockquote>
<p>The scattered and ineffectual responses are an unfortunate casualty of the ubiquitous poor online examples found on the Internet. No doubt you&#8217;ve seen something like this before:</p>
<pre class="prettyprint"><code>public interface IVehicle {
    int NumberOfPassengers { get; }
}

public class Car : IVehicle {
    public int NumberOfPassengers { get { return 4; } }
}

public class Bus : IVehicle {
    public int NumberOfPassengers { get { return 20; } }
}</code></pre>
<p>I can&#8217;t help but have visions of rich objects that model the physical world so well they put an end to wars and world hunger. You know, methods like <font face="Courier New" size="2">Bark()</font> on a <font face="Courier New" size="2">Dog</font> object. These examples aren&#8217;t <em>wrong</em> per se, but they usher the reader down a predictable and dead-end path. It&#8217;s like the horribly cliché <a href="http://en.wikipedia.org/wiki/Thinking_outside_the_box">nine dots puzzle</a> in which the goal is to link all 9 dots using four straight lines or less, without lifting the pen.</p>
<p>Common sense suggests it can&#8217;t be done because we have subconsciously imposed a false restriction that the lines must be within the boundaries of the square (I won&#8217;t insult you with the hopelessly worn out catch phrase). The point I&#8217;m trying to make here is the examples out there unwittingly set us up for failure. In social science this is called <a href="http://en.wikipedia.org/wiki/Framing_(social_sciences)">framing</a>. The human brain is an impressive problem solving machine, but we can be easily fooled by framing a problem in a way that our stereotypes and assumptions obscure the often obvious answer.</p>
<p>In the case of interfaces, the examples suggest the concrete implementations are mutually exclusive physical concepts like <font face="Courier New" size="2">Car</font> and <font face="Courier New" size="2">Bus</font>, or perhaps <font face="Courier New" size="2">SqlUserStore</font> and <font face="Courier New" size="2">LdapUserStore</font>. It&#8217;s an easy concept to latch on to, and it&#8217;s the bane of good object oriented design.</p>
<p>To think of a user store as a <em>thing</em> is a mistake. <font face="Courier New" size="2">IUserStore</font> defines a seam in which responsibility crosses a boundary. In an MVC application, it&#8217;s the seam between the controller&#8217;s routing responsibility and the model&#8217;s business logic. If you only have one implementation of <font face="Courier New" size="2">IUserStore</font> , then you&#8217;d better take another look because <a href="http://c2.com/cgi/wiki$?WhatIsaSmell">that&#8217;s a smell</a>.</p>
<p>The place to start looking is within your one and only implementation. Where is the logic about sending a confirmation email or checking if the username is available? Chances are it ended up in the controller leaving your model anemic or it ended up in your model violating the single responsibility principle. Either way it&#8217;s a big fail sandwich.</p>
<p>Again, this is because of the false assumption that implementations are mutually exclusive as in the <font face="Courier New" size="2">Car</font> and <font face="Courier New" size="2">Bus </font>example. In other words, if I have a <font face="Courier New" size="2">Car</font> , then I don&#8217;t have a <font face="Courier New" size="2">Bus</font>. This is the wrong way to think of objects. Of course they can be mutually exclusive, but they are far more powerful when they are <em>composable</em>. Consider these implementations of <font face="Courier New" size="2">IUserService</font>:</p>
<ul>
<li><font face="Courier New" size="2">EmailConfirmationUserService</font> </li>
<li><font face="Courier New" size="2">ValidatingUserService</font> </li>
<li><font face="Courier New" size="2">SqlUserService</font> </li>
<li><font face="Courier New" size="2">CachingUserService</font> </li>
</ul>
<p>Each concern is orthogonal to each other concern and they are combined together to create the overall behavior of the system. The interface facilitates composition which is the key to high-quality, robust software. So the real problem isn&#8217;t that interfaces are overused, it&#8217;s that interfaces are squandered.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-interfaces-no-excuses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Inheritance is Evil: The Epic Fail of the DataAnnotationsModelBinder</title>
		<link>http://www.agileatwork.com/inheritance-is-evil-the-story-of-the-epic-fail-of-dataannotationsmodelbinder/</link>
		<comments>http://www.agileatwork.com/inheritance-is-evil-the-story-of-the-epic-fail-of-dataannotationsmodelbinder/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 14:52:10 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Decorator Pattern]]></category>
		<category><![CDATA[Single Responsibility Principle]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/?p=312</guid>
		<description><![CDATA[The DataAnnotationsModelBinder is a pretty neat little class that enforces validation attributes on models like this one:
public class Product {
    public int Id { get; set; }

    [Required]
    public string Description { get; set; }

    [Required]
    [RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]
    [...]]]></description>
			<content:encoded><![CDATA[<p>The <font face="Courier New" size="2">DataAnnotationsModelBinder</font> is a pretty neat little class that enforces validation attributes on models like this one:</p>
<pre class="prettyprint"><code>public class Product {
    public int Id { get; set; }

    [Required]
    public string Description { get; set; }

    [Required]
    [RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]
    public decimal UnitPrice { get; set; }
}</code></pre>
<p>Just for the record, this is a <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471">cool bit of code</a> that was released to the community for backseat drivers like me to use and complain about. I&#8217;m really only bitter because I can&#8217;t use it. Let&#8217;s take a peek at the source code to see why:</p>
<pre class="prettyprint"><code>/// &lt;summary&gt;
/// An implementation of IModelBinder which is designed to be a replacement
/// default model binder, adding the functionality of validation via the validation
/// attributes in System.ComponentModel.DataAnnotations from .NET 4.0.
/// &lt;/summary&gt;
public class DataAnnotationsModelBinder : DefaultModelBinder {
    ...
}</code></pre>
<p>The problem with this class is that it&#8217;s not just about validation. It&#8217;s more about binding with validation sprinkled in. The author even states this as a design goal with the comment &#8220;designed to be a replacement default model binder.&#8221; This is a violation of the Single Responsibility Principle and it&#8217;s the reason I can&#8217;t use it. The <font face="Courier New" size="2">DefaultModelBinder</font> does some basic reflection mapping of form elements to model properties. That&#8217;s cool, but what about a controller action that takes json, xml, or anything slightly more complicated than what the default binder can handle?</p>
<p>I&#8217;ll tell you what happens. You write a <a href="http://www.agileatwork.com/custom-model-binder-in-asp-net-mvc/">custom model binder</a> which is pretty easy and happens to be a pretty rad extension point in the MVC framework. Consider this model binder that deserializes json:</p>
<pre class="prettyprint"><code>public class JsonModelBinder&lt;T&gt; : IModelBinder {
    private string key;

    public JsonModelBinder(string requestKey) {
        this.key = requestKey;
    }

    public object BindModel(ControllerContext controllerContext, ...) {
        var json = controllerContext.HttpContext.Request[key];
        return new JsonSerializer().Deserialize&lt;T&gt;(json);
    }
}</code></pre>
<p>That&#8217;s pretty cool, but now I&#8217;ve lost my validation! This my friend is the evil of inheritance and the epic fail of the <font face="Courier New" size="2">DataAnnotationsModelBinder</font>. So what’s wrong with inheritance, isn’t that what OOP is all about? The short answer is no (the long answer is also no.)</p>
<p><img title="peter-venkman-ghostbusters" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="224" alt="peter-venkman-ghostbusters" src="http://www.agileatwork.com/wp-content/uploads/2010/01/petervenkmanghostbusters.jpg" width="300" border="0" /> </p>
<blockquote>
<p>Human sacrifice, dogs and cats living together&#8230; mass hysteria! &#8212; Dr. Peter Venkman</p>
</blockquote>
<p>Inheritance is pretty enticing especially coming from procedural-land and it often looks deceptively elegant. I mean all I need to do is add this one bit of functionality to another other class, right? Well, one of the problems is that inheritance is probably the worst form of coupling you can have. Your base class breaks encapsulation by exposing implementation details to subclasses in the form of protected members. This makes your system rigid and fragile.</p>
<p>The more tragic flaw however is the new subclass brings with it all the baggage and opinion of the inheritance chain. Why does a model that enforces validation attributes care how the model is constructed? The answer is it shouldn&#8217;t, and to add insult to injury, the better design is actually easier to implement. Listen closely and you may hear the wise whispers of our forefathers&#8230;</p>
<p><img title="Ward Cunningham" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="117" alt="Ward Cunningham" src="http://www.agileatwork.com/wp-content/uploads/2010/01/ward.jpg" width="92" border="0" /> <img title="Martin Fowler" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="117" alt="Martin Fowler" src="http://www.agileatwork.com/wp-content/uploads/2010/01/martin.jpg" width="94" border="0" /> <img title="Kent Beck" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="117" alt="Kent Beck" src="http://www.agileatwork.com/wp-content/uploads/2010/01/kent.jpg" width="78" border="0" /> <img title="Robert Martin" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="117" alt="Robert Martin" src="http://www.agileatwork.com/wp-content/uploads/2010/01/robert.jpg" width="87" border="0" /> </p>
<blockquote>
<p>Use the decorator pattern.</p>
</blockquote>
<p>Is this really going to solve all my problems? The short answer is yes. Let&#8217;s take a look:</p>
<pre class="prettyprint"><code>public class BetterDataAnnotationsModelBinder : IModelBinder {
    private IModelBinder binder;

    public BetterDataAnnotationsModelBinder(IModelBinder binder) {
        this.binder = binder;
    }

    public object BindModel(ControllerContext controllerContext, ...) {
        var model = binder.BindModel(controllerContext, bindingContext);
        AddValidationErrorsToModelState(model, controllerContext);
        return model;
    }

    ...
}</code></pre>
<p>Now all this class does is enforce validation and we can use whatever model binder we want to construct our object. Let&#8217;s wire this up in the Global.asax real quick: </p>
<pre class="prettyprint"><code>var productModelBinder = new JsonModelBinder&lt;Product&gt;("product");

ModelBinders.Binders.Add(
    typeof(Product),
    new BetterDataAnnotationsModelBinder(productModelBinder));</code></pre>
<p>This is cool for the following reasons:</p>
<ol>
<li>We are not coupled to the <font face="Courier New" size="2">DefaultModelBinder</font>. This means we don&#8217;t know or care about the structure and implementation details of it so it&#8217;s free to change in the next version of ASP.NET MVC. </li>
<li>The code is simpler because it is only about validation. </li>
<li>The behavior is composable. This means we can add validation to any model binder (like our json model binder) and bolt on more responsibilities with a chain of decorators. How about converting <font face="Courier New" size="2">DateTime</font> fields to UTC or striping formatting characters from phone numbers? </li>
<li>It&#8217;s easy to test. </li>
</ol>
<p>You can substitute a decorator for a subclass in most cases and in most cases it&#8217;s the right choice. You&#8217;re better off making the decorator your default choice and only settle for inheritance when you really need it.</p>
<p><img title="kip" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="184" alt="kip" src="http://www.agileatwork.com/wp-content/uploads/2010/01/kip.jpg" width="170" border="0" /> </p>
<blockquote>
<p>&#8230;don&#8217;t be jealous that I&#8217;ve been chatting online with babes all day. Besides, we both know that I&#8217;m training to be a cage fighter. &#8212; Kip</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/inheritance-is-evil-the-story-of-the-epic-fail-of-dataannotationsmodelbinder/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Custom Model Binder in ASP.NET MVC</title>
		<link>http://www.agileatwork.com/custom-model-binder-in-asp-net-mvc/</link>
		<comments>http://www.agileatwork.com/custom-model-binder-in-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 22:59:22 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Command Query Separation]]></category>
		<category><![CDATA[Decorator Pattern]]></category>
		<category><![CDATA[Single Responsibility Principle]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/?p=298</guid>
		<description><![CDATA[The default model binder or DataAnnotationsModelBinder in ASP.NET MVC works well for simple data structures that basically map properties directly to form elements, but it quickly breaks down in a real world application. Take this simple scenario:

The built-in model binder can handle the easy fields like FirstName, LastName, and Email, but it doesn’t know how [...]]]></description>
			<content:encoded><![CDATA[<p>The default model binder or <font face="Courier New" size="2">DataAnnotationsModelBinder</font> in ASP.NET MVC works well for simple data structures that basically map properties directly to form elements, but it quickly breaks down in a real world application. Take this simple scenario:</p>
<p><img title="brimley" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="277" alt="brimley" src="http://www.agileatwork.com/wp-content/uploads/2009/12/brimley.png" width="253" border="0" /></p>
<p>The built-in model binder can handle the easy fields like <font face="Courier New" size="2">FirstName</font>, <font face="Courier New" size="2">LastName</font>, and <font face="Courier New" size="2">Email</font>, but it doesn’t know how to deal with the roles. This is where the custom model binder comes in:</p>
<pre class="prettyprint"><code>public class UserModelBinder : IModelBinder {
    private readonly IModelBinder binder;

    public UserModelBinder(IModelBinder binder) {
        this.binder = binder;
    }

    public object BindModel(ControllerContext controllerContext, ...) {
        var user = (User)binder.BindModel(controllerContext, bindingContext);
        AddRoles(user, controllerContext);
        return user;
    }

    private static void AddRoles(User user, ControllerContext controllerContext) {
        foreach (var role in GetRoles(controllerContext)) {
            user.Add(role);
        }
    }

    private static IEnumerable&lt;Role&gt; GetRoles(ControllerContext controllerContext) {
        var roles = controllerContext.HttpContext.Request["roles"];
        if (roles == null) yield break;
        foreach (var roleId in roles.Split(',')) {
            yield return (Role)Convert.ToInt32(roleId);
        }
    }
}</code></pre>
<p>And it gets wired-up in the Global.asax like this:</p>
<pre class="prettyprint"><code>var defaultBinder = new DataAnnotationsModelBinder();
ModelBinders.Binders.DefaultBinder = defaultBinder;
ModelBinders.Binders.Add(typeof(User), new UserModelBinder(defaultBinder));</code></pre>
<p>Because <font face="Courier New" size="2">UserModelBinder</font> is a decorator, it preserves the base functionality (like validation) of the default binder and only adds the part about mapping the roles. This is good stuff because it keeps construction of the model out of the controller. That&#8217;s the Single-Responsibility Principle in action.</p>
<h3>Command Query Separation</h3>
<p>The two functions <font face="Courier New" size="2">AddRoles</font>, and <font face="Courier New" size="2">GetRoles</font> are an example of command query separation (CQS). It would be easy to combine those two functions together and in fact that&#8217;s how it looked at first. So why bother separating them? Well it doesn&#8217;t <em>really</em> matter in this simple case, but it’s like how I tell my 3 year-old son to move his milk cup away from the edge of the table. I figure it’s a good habit that will prevent a few spills in the long run. The idea with CQS is there is a natural seam between finding objects and doing stuff with them. I buy that. I expect <font face="Courier New" size="2">GetRoles</font> to be more volatile than <font face="Courier New" size="2">AddRoles</font> or at least change for different reasons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/custom-model-binder-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Captcha and Inversion of Control</title>
		<link>http://www.agileatwork.com/captcha-and-inversion-of-control/</link>
		<comments>http://www.agileatwork.com/captcha-and-inversion-of-control/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 06:09:18 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Inversion of Control]]></category>
		<category><![CDATA[Single Responsibility Principle]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/?p=98</guid>
		<description><![CDATA[
I made a few tweaks to a captcha library I found here and basically wrapped their CaptchaImage object in a service interface to use in my application. Pretty easy stuff, but I didn’t get it right the first time.
What’s wrong with this class? (hint: it’s highlighted in yellow)
public class HttpContextCacheCaptchaProvider : ICaptchaProvider
{
    [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Inversion of Control" border="0" alt="Inversion of Control" src="http://www.agileatwork.com/wp-content/uploads/2009/06/lorenzoflip.jpg" width="240" height="159" /></p>
<p>I made a few tweaks to a captcha library I found <a href="http://www.codeproject.com/KB/aspnet/CaptchaImage.aspx">here</a> and basically wrapped their <font size="2" face="Courier New">CaptchaImage</font> object in a service interface to use in my application. Pretty easy stuff, but I didn’t get it right the first time.</p>
<p>What’s wrong with this class? <font size="2"><em>(hint: it’s highlighted in yellow)</em></font></p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> HttpContextCacheCaptchaProvider : ICaptchaProvider
{
    <span class="kwrd">private</span> <span class="kwrd">const</span> <span class="kwrd">string</span> httpContextCacheKey = <span class="str">&quot;4D795A45-8015-475C-A6C4-765B09EB9955&quot;</span>;
    <span class="kwrd">private</span> ICaptchaImageFactory factory;
    <span class="kwrd">private</span> HttpContextBase context;

    <span class="kwrd">public</span> HttpContextCacheCaptchaProvider(ICaptchaImageFactory factory, HttpContextBase context)
    {
        <span class="kwrd">this</span>.factory = factory;
        <span class="kwrd">this</span>.context = context;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Render(Stream stream)
    {
        CaptchaImage captchaImage = factory.Create();

        <span style="background: #ffffc0">context.Cache[httpContextCacheKey] = captchaImage.Text;</span>

        <span class="kwrd">using</span> (Bitmap bitmap = captchaImage.RenderImage())
        {
            bitmap.Save(stream, ImageFormat.Jpeg);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">bool</span> Verify(<span class="kwrd">string</span> text)
    {
        <span style="background: #ffffc0"><span class="kwrd">string</span> captchaText = (<span class="kwrd">string</span>)context.Cache[httpContextCacheKey];</span>

        <span class="kwrd">if</span> (text == <span class="kwrd">null</span> || captchaText == <span class="kwrd">null</span>)
            <span class="kwrd">return</span> <span class="kwrd">false</span>;
        <span class="kwrd">else</span>
            <span class="kwrd">return</span> text.ToLower().Equals(captchaText.ToLower());
    }
}</pre>
<p>Perhaps your nose can lead you in the right direction. The smell is <a href="http://c2.com/cgi/wiki?CodeSmellMetrics">hard to test</a>, and it’s hard to test because it requires mocking the <font size="2" face="Courier New">HttpContextBase</font>. You might say “no problem, I can blast out a stub with <a href="http://code.google.com/p/moq/">Moq</a> in no time” but you’re missing the real problem. That would be like taking aspirin for a brain tumor.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="arnold" border="0" alt="arnold" src="http://www.agileatwork.com/wp-content/uploads/2009/06/arnold.jpg" width="208" height="241" /></p>
<blockquote>
<p>It’s not a tumor</p>
</blockquote>
<p>The real problem is this class is violating the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Single Responsibility Principle</a> (SRP) by doing more than one thing. I don’t mean the two methods <font size="2" face="Courier New">Render()</font> and <font size="2" face="Courier New">Verify()</font>, those are a cohesive unit operating on the same data. The other thing is <em>lifetime management</em>. Look how simple the class gets when you invert control and take out the notion of lifetime management:</p>
<pre class="csharpcode">[Serializable]
<span class="kwrd">public</span> <span class="kwrd">class</span> LifetimeManagedCaptchaProvider : ICaptchaProvider
{
    <span class="kwrd">private</span> ICaptchaImageFactory factory;
    <span class="kwrd">private</span> <span class="kwrd">string</span> captchaText;

    <span class="kwrd">public</span> LifetimeManagedCaptchaProvider(ICaptchaImageFactory factory)
    {
        <span class="kwrd">this</span>.factory = factory;
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Render(Stream stream)
    {
        CaptchaImage captchaImage = factory.Create();

        <span style="background: #ffffc0">captchaText = captchaImage.Text;</span>

        <span class="kwrd">using</span> (Bitmap bitmap = captchaImage.RenderImage())
        {
            bitmap.Save(stream, ImageFormat.Jpeg);
        }
    }

    <span class="kwrd">public</span> <span class="kwrd">bool</span> Verify(<span class="kwrd">string</span> text)
    {
        <span class="kwrd">if</span> (text == <span class="kwrd">null</span> || captchaText == <span class="kwrd">null</span>)
            <span class="kwrd">return</span> <span class="kwrd">false</span>;
        <span class="kwrd">else</span>
            <span class="kwrd">return</span> text.ToLower().Equals(captchaText.ToLower());
    }
}</pre>
<p>Now this class is a breeze to test and all you have to do is register it like this:</p>
<pre class="csharpcode">Container.RegisterType&lt;ICaptchaProvider, LifetimeManagedCaptchaProvider&gt;(
    <span class="kwrd">new</span> HttpSessionStateLifetimeManager());</pre>
<p>The moral of the story is let your IoC container do things it’s good at.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/captcha-and-inversion-of-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

