<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Test Driven Development</title>
        <link>http://geekswithblogs.net/Podwysocki/category/4798.aspx</link>
        <description>Test Driven Development</description>
        <language>en-US</language>
        <copyright>Matthew Podwysocki</copyright>
        <managingEditor>matthew.podwysocki@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Unity Community Contributions and Interception</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/04/11/121194.aspx</link>
            <description>Now that Unity has been released into the wild, there has definitely been a bit of interest swirling around it.  One of my key wants for a good IoC container is basic interception capabilities.  My criteria for evaluating a container usually comes down to the following:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Configurability (XML, DSL, Code)&lt;/li&gt;
    &lt;li&gt;Dependency Resolution, usually opinionated&lt;/li&gt;
    &lt;li&gt;Lifetime Management (Per Thread, Pooled, Singleton, Transient, etc)&lt;/li&gt;
    &lt;li&gt;Extensibility for Interception&lt;/li&gt;
&lt;/ul&gt;
So, I realized that Unity was missing some of these things in the first go around.  Since Unity was built on top of ObjectBuilder2, a next generation version of the often maligned ObjectBuilder which also included some sample DI containers and a flexible interception model.  Today's post will cover that and a bit more.  I realize that I still am working on a post of AOP in the Enterprise and Spring.NET which is coming soon.&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
&lt;br /&gt;
Where We Are&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
But, before we begin today, let's see what we've already covered in the past:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/04/07/unity-1-0-released-into-the-wild.aspx"&gt;Unity 1.0 Released into the Wild&lt;/a&gt;&lt;br /&gt;
    Unity 1.0 released and available on MSDN.  Unfortunately, registration is required...&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/27/ioc-and-unity-configuration-changes-for-the-better.aspx"&gt;IoC and Unity - Configuration Changes for the Better&lt;/a&gt;&lt;br /&gt;
    Covers the configuration changes to allow for better parameterization for constructors&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/25/ioc-and-unity-the-basics-and-interception.aspx"&gt;IoC and Unity - The Basics and Interception&lt;/a&gt;&lt;br /&gt;
    Talking about the basics of IoC containers and the interception models&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/07/ioc-container-unity-and-breaking-changes-galore.aspx"&gt;IoC Container, Unity and Breaking Changes Galore&lt;/a&gt;&lt;br /&gt;
    Covers the breaking changes made from the old Unity drop to the new one&lt;br /&gt;
    &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/04/ioc-containers-unity-and-objectbuilder2-the-saga-continues.aspx"&gt;&lt;br /&gt;
    &lt;/a&gt;     &lt;/li&gt;
    &lt;li&gt;&lt;a href="javascript:void(0);/*1206509408817*/"&gt;IoC Containers, Unity and ObjectBuilder2 - The Saga Continues&lt;/a&gt;&lt;br /&gt;
    Managing instances and parameter mapping resolution&lt;br /&gt;
    &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx"&gt;&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/02/26/ioc-and-the-unity-application-block-once-again.aspx"&gt;IoC and the Unity Application Block Once Again&lt;/a&gt;&lt;br /&gt;
    Setter Injection versus Constructor Injection and PostSharp4Unity&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/02/22/ioc-and-the-unity-application-block-going-deeper.aspx"&gt;IoC and the Unity Application Block - Going Deeper&lt;/a&gt;&lt;br /&gt;
    Constructor Injection and comparing Unity with Castle Windsor&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/02/18/ioc-and-the-unity-application-block.aspx"&gt;IoC and the Unity Application Block&lt;/a&gt;&lt;br /&gt;
    Covering ObjectBuilder and Unity Application Block&lt;/li&gt;
&lt;/ul&gt;
Now that we've look at the history of this series, let's go ahead and get started.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Unity Contributions&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Since Unity was released last Friday, there has been a community effort much like the ASP.NET MVC Contributions, &lt;a href="http://www.codeplex.com/MVCContrib"&gt;MVCContrib&lt;/a&gt;, called &lt;a href="http://www.codeplex.com/unitycontributions"&gt;Unity Community Contributions&lt;/a&gt;.  This project is intended to fill in the gaps where the community feels that Unity can be extended, much like most other IoC containers.  As I stated above, one of those crucial things that I thought was missing was taking the ObjectBuilder2 Interception model and applying it towards Unity.  I wasn't interested as much in the Policy Injection Application Block, although nice, is a bit heavyweight for the basic operations I would like.  Instead, the OB2 would suffice for most things that I'd want with a container.  So, that led me to another topic...&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;ObjectBuilder2 Interception == Unity Interception?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Since I was particularly motivated to see the OB2 Interception model pushed into Unity, I decided to give it a go myself.  For the most part, I was successful in a way, but I wasn't using the right extensibility model.  From that point, I got in contact with&lt;a href="http://blogs.msdn.com/scottdensmore/"&gt; Scott Densmore&lt;/a&gt;, a PM within the Patterns &amp;amp; Practices group and one of the authors of ObjectBuilder2 along with &lt;a href="http://bradwilson.typepad.com/"&gt;Brad Wilson&lt;/a&gt;.  From that point, he was able to take the original OB2 Interception model and fit it nicely into the Unity extensibility model.  The code is now available on the Unity Community Contributions and you can find those commits by Scott &lt;a href="http://www.codeplex.com/unitycontributions/SourceControl/ListDownloadableCommits.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
So, let's take a look at what it entails.  As I tell most people, you learn the most about the software with good unit, I mean behavioral tests where I can really grok the intent of the code much better than most documentation.  I encourage most people to do the same.  I'd rather stay away from those projects that don't have tests to back up their work.&lt;br /&gt;
&lt;br /&gt;
Like I said before, ObjectBuilder2 had several ways of intercepting calls.  There are several interception strategies worth mentioning:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Virtual Method interception&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Interface Method interception&lt;/li&gt;
    &lt;li&gt;.NET Remoting interception (MarshalByRefObject)&lt;/li&gt;
&lt;/ul&gt;
From that, you have two ways of registering your interest for interception:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Intercept via code&lt;/li&gt;
    &lt;li&gt;Intercept via attributes&lt;/li&gt;
&lt;/ul&gt;
Now that we've laid down the basics, let's take a look at some of the unit tests.  You'll notice that &lt;a href="http://codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; was used for the unit tests.  Yes, I know, I've mentioned it a few times lately.  Anyhow, let's look first at virtual method interception.&lt;br /&gt;
&lt;br /&gt;
Before we get started on that, in order to perform interception, we need to implement the IInterceptionHandler interface.  For the unit tests, this will be used to record the various actions that happened during the interception process.  But you can imagine it to do any number of things such as logging, transaction management, security and so on.  Any of those cross cutting concerns, really.&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 static\cf3  \cf1 class\cf3  \cf4 IoC\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 static\cf3  \cf5 IDependencyResolver\cf3  resolver;\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  \cf1 void\cf3  Initialize(\cf5 IDependencyResolver\cf3  resolver)\par ??        \{\par ??            \cf4 IoC\cf3 .resolver = resolver;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;()\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;();\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;(\cf1 string\cf3  name)\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;(name);\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;&lt;br /&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 153, 0);"&gt;public delegate&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IMethodReturn&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;InovkeHandlerDelegate&lt;/span&gt;&lt;span style="color: rgb(0, 204, 255);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IMethodInvocation&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;call,&lt;/span&gt;&lt;br /&gt;
                                                        &lt;span style="color: rgb(43, 145, 175);"&gt;GetNextHandlerDelegate&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;getNext);&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
    &lt;span style="color: rgb(255, 153, 0);"&gt;public delegate&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;InovkeHandlerDelegate&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;GetNextHandlerDelegate&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;();&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
    &lt;span style="color: rgb(255, 153, 0);"&gt;public interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: rgb(255, 255, 255);"&gt;     {&lt;/span&gt;&lt;br /&gt;
        &lt;span style="color: rgb(43, 145, 175);"&gt;IMethodReturn &lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;Invoke(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IMethodInvocation&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;call,&lt;/span&gt;&lt;br /&gt;
                             &lt;span style="color: rgb(43, 145, 175);"&gt;GetNextHandlerDelegate&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;getNext);&lt;/span&gt;&lt;br style="color: rgb(255, 255, 255);" /&gt;
&lt;span style="color: rgb(255, 255, 255);"&gt;     }&lt;/span&gt;&lt;br style="color: rgb(255, 255, 255);" /&gt;
&lt;span style="color: rgb(255, 255, 255);"&gt; } &lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;   &lt;span style="color: rgb(255, 153, 0);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;RecordingHandler &lt;/span&gt;: &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;&lt;br /&gt;
    {&lt;br /&gt;
        &lt;span style="color: rgb(255, 153, 0);"&gt;readonly string &lt;/span&gt;message;&lt;br /&gt;
&lt;br /&gt;
        [&lt;span style="color: rgb(255, 255, 0);"&gt;InjectionConstructor&lt;/span&gt;]&lt;br /&gt;
        &lt;span style="color: rgb(255, 153, 0);"&gt;public &lt;/span&gt;RecordingHandler()&lt;br /&gt;
        {&lt;br /&gt;
            message = &lt;span style="color: rgb(0, 255, 0);"&gt;""&lt;/span&gt;;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;span style="color: rgb(255, 153, 0);"&gt;public &lt;/span&gt;RecordingHandler(&lt;span style="color: rgb(255, 153, 0);"&gt;string &lt;/span&gt;message)&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;this&lt;/span&gt;.message = &lt;span style="color: rgb(255, 153, 0);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 255, 0);"&gt;" ({0})"&lt;/span&gt;, message);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        &lt;span style="color: rgb(255, 153, 0);"&gt;public &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IMethodReturn&lt;/span&gt; Invoke(&lt;span style="color: rgb(43, 145, 175);"&gt;IMethodInvocation&lt;/span&gt; call,&lt;br /&gt;
                                    &lt;span style="color: rgb(43, 145, 175);"&gt;GetNextHandlerDelegate&lt;/span&gt; getNext)&lt;br /&gt;
        {&lt;br /&gt;
            &lt;span style="color: rgb(255, 255, 0);"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: rgb(0, 255, 0);"&gt;"Before Method"&lt;/span&gt; + message);&lt;br /&gt;
            &lt;span style="color: rgb(43, 145, 175);"&gt;IMethodReturn &lt;/span&gt;result = getNext().Invoke(call, getNext);&lt;br /&gt;
            &lt;span style="color: rgb(255, 255, 0);"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: rgb(0, 255, 0);"&gt;"After Method" &lt;/span&gt;+ message);&lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;return &lt;/span&gt;result;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
We have the ability through the Invoke method to do things before the method as well as after.  Should we need to modify values before the method is called, we can go ahead and do so.  Now that we looked at that, let's get to some unit tests.  First off, let's look at interception through just code.  I like this approach as opposed to attributes due to not cluttering the domain model and making it more configurable at run time.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 static\cf3  \cf1 class\cf3  \cf4 IoC\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 static\cf3  \cf5 IDependencyResolver\cf3  resolver;\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  \cf1 void\cf3  Initialize(\cf5 IDependencyResolver\cf3  resolver)\par ??        \{\par ??            \cf4 IoC\cf3 .resolver = resolver;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;()\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;();\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;(\cf1 string\cf3  name)\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;(name);\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;            [&lt;span style="color: yellow;"&gt;Fact&lt;/span&gt;]&lt;br /&gt;
            &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptViaCode()&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Clear();&lt;br /&gt;
                &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;();&lt;br /&gt;
                container.AddNewExtension&amp;lt;&lt;span style="color: rgb(255, 255, 0);"&gt;InterceptionExtension&lt;/span&gt;&amp;gt;();&lt;br /&gt;
               container.Configure&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionConfiguration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;().&lt;/span&gt;InterceptVirtual&amp;lt;&lt;span style="color: rgb(255, 255, 0);"&gt;SpyVirtual&lt;/span&gt;&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                   (&lt;span style="color: rgb(255, 153, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(255, 255, 0);"&gt;SpyVirtual&lt;/span&gt;).GetMethod(&lt;span style="color: rgb(0, 255, 0);"&gt;"InterceptedMethod"&lt;/span&gt;), &lt;span style="color: rgb(255, 153, 0);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;RecordingHandler&lt;/span&gt;());&lt;br /&gt;
&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;SpyVirtual&lt;/span&gt; obj = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;SpyVirtual&lt;/span&gt;&amp;gt;();&lt;br /&gt;
                obj.InterceptedMethod();&lt;br /&gt;
                obj.NonInterceptedMethod();&lt;br /&gt;
&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(4, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Count);&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: rgb(0, 255, 0);"&gt;"Before Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[0]);&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: rgb(0, 255, 0);"&gt;"In Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[1]);&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: rgb(0, 255, 0);"&gt;"After Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[2]);&lt;br /&gt;
                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: rgb(0, 255, 0);"&gt;"In Non-Intercepted Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[3]);&lt;br /&gt;
            }&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;SpyVirtual&lt;/span&gt;&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(255, 153, 0);"&gt;public virtual void&lt;/span&gt; InterceptedMethod()&lt;br /&gt;
                {&lt;br /&gt;
                    &lt;span style="color: rgb(255, 255, 0);"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: rgb(0, 255, 0);"&gt;"In Method"&lt;/span&gt;);&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
                &lt;span style="color: rgb(255, 153, 0);"&gt;public void&lt;/span&gt; NonInterceptedMethod()&lt;br /&gt;
                {&lt;br /&gt;
                    &lt;span style="color: rgb(255, 255, 0);"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: rgb(0, 255, 0);"&gt;"In Non-Intercepted Method"&lt;/span&gt;);&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
                &lt;span style="color: rgb(255, 153, 0);"&gt;public virtual void&lt;/span&gt; ThrowsException()&lt;br /&gt;
                {&lt;br /&gt;
                    &lt;span style="color: rgb(255, 255, 0);"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: rgb(0, 255, 0);"&gt;"In Method"&lt;/span&gt;);&lt;br /&gt;
                    &lt;span style="color: rgb(255, 153, 0);"&gt;throw new&lt;/span&gt; Exception(&lt;span style="color: rgb(0, 255, 0);"&gt;"This is my exception!"&lt;/span&gt;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
As you see above, we can simply register our interest through the registration of the InterceptionExtension and then set up the configuration through the IInterceptionConfiguration.  From that point, we then say which kind of interception we want whether it be virtual, remoting or interfaces.  We specify the method we want to intercept by name.&lt;br /&gt;
&lt;br /&gt;
You can also do the interception through the use of attributes.  From this point, we need to decorate our methods with the attribute and the particular interception handler we want to use.  We need to be aware of which interception strategy we're using as well when we decorate our classes.  You can intercept methods as well as property accessors by decorating the get or set.  Below is a simple example of a virtual interceptor registration.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 static\cf3  \cf1 class\cf3  \cf4 IoC\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 static\cf3  \cf5 IDependencyResolver\cf3  resolver;\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  \cf1 void\cf3  Initialize(\cf5 IDependencyResolver\cf3  resolver)\par ??        \{\par ??            \cf4 IoC\cf3 .resolver = resolver;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;()\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;();\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;(\cf1 string\cf3  name)\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;(name);\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;             &lt;span style="color: rgb(255, 153, 0);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;SpyVirtualAttributes&lt;/span&gt;&lt;br /&gt;
            {&lt;br /&gt;
                [&lt;span style="color: rgb(255, 255, 0);"&gt;VirtualIntercept&lt;/span&gt;(&lt;span style="color: rgb(255, 153, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(255, 255, 0);"&gt;RecordingHandler&lt;/span&gt;))]&lt;br /&gt;
                &lt;span style="color: rgb(255, 153, 0);"&gt;public virtual void&lt;/span&gt; InterceptedMethod()&lt;br /&gt;
                {&lt;br /&gt;
                    &lt;span style="color: rgb(255, 255, 0);"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: rgb(0, 255, 0);"&gt;"In Method"&lt;/span&gt;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;/p&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
I'm not going to post all of the tests, but I want to give you an idea of the power of this.  It's still early in the process and there is some cleanup still going on.  But, I encourage you to pick up the source, read it, grok it, give it a try and give feedback. &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, the extensibility model of Unity works in that we can add interception to Unity.  So, we can start thinking about moving our cross cutting concerns to these layers should we so choose if Unity is your container of choice.  There are plenty of containers out there to choose from, so it's best to give them all a try and pick one based upon features, programming style, and heck, maybe even licensing.  I'll be showing some of this stuff off tomorrow at the CMAP Code Camp, so if you'll be at my 1PM session, be prepared.  Until next time... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/11/121194.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/11/121194.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121194"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121194" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/121194.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/04/11/121194.aspx</guid>
            <pubDate>Sat, 12 Apr 2008 00:35:05 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/121194.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/04/11/121194.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/121194.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/121194.aspx</trackback:ping>
        </item>
        <item>
            <title>xUnit.net RC3 Just Released</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/04/10/121177.aspx</link>
            <description>Well, &lt;a href="http://bradwilson.typepad.com/blog/"&gt;Brad Wilson&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/jamesnewkirk/"&gt;Jim Newkirk&lt;/a&gt; must really be busy lately.  After I talked about the release of xUnit.net RC2, just today, Brad announced the release of RC3.  As always, you can find the latest bits &lt;a href="http://codeplex.com/xunit"&gt;here&lt;/a&gt;.  This fixes a number of bugs and adds &lt;a href="http://ccnet.thoughtworks.com/"&gt;CruiseControl.NET&lt;/a&gt; and &lt;a href="http://asp.net/mvc/"&gt;ASP.NET MVC Preview 2&lt;/a&gt; support as well in addition to the &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper 3.1&lt;/a&gt; and &lt;a href="http://www.testdriven.net/"&gt;TestDriven.NET&lt;/a&gt; support.  For more information about it, check out Brad's post &lt;a href="http://bradwilson.typepad.com/blog/2008/04/xunitnet-10-rc3.html"&gt;here&lt;/a&gt;.  More or less, they are feature complete for version 1.0 and the only that I think really is needed at this point is a decent GUI runner and that's well acknowledged as something they are working on.  Visual Studio integration would be nice as well...&lt;br /&gt;
&lt;br /&gt;
For my other posts in this series, check them out here:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/31/xunit-net-rc2-released.aspx"&gt;xUnit.net RC2 Released&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/04/04/relooking-at-xunit-net-rc2.aspx"&gt;Relooking at xUnit.net RC2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
If you were in attendance at last night's &lt;a href="http://rocknug.org/"&gt;RockNUG&lt;/a&gt; appearance, all tests for my demos were using xUnit.net, so I am actively using it right now and will be for my &lt;a href="http://www.cmap-online.org/CodeCamp/"&gt;CMAP Code Camp&lt;/a&gt; appearance this weekend.  However, I did not show the GUI runner because, well, it's not there yet, and instead, the console runner works just fine, thank you.  So, go ahead and pick up the latest bits and give the team feedback!&lt;br /&gt;
&lt;br /&gt;
One last note regarding Brad, he was &lt;a href="http://howsoftwareisbuilt.com/2008/04/08/interview-with-brad-wilson-software-developer-officelabs-microsoft/"&gt;recently interviewed&lt;/a&gt; by &lt;a href="http://howsoftwareisbuilt.com/about-scott-swigart/"&gt;Scott Swigart&lt;/a&gt; and &lt;a href="http://howsoftwareisbuilt.com/about-sean-campbell/"&gt;Sean Campbell&lt;/a&gt; over at &lt;a href="http://howsoftwareisbuilt.com"&gt;How Software Is Built&lt;/a&gt; and gives some interesting insights in the open source world inside and outside Microsoft and his contributions to it.  Very good interview and well worth the time to read.
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/10/121177.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/10/121177.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121177"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121177" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/121177.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/04/10/121177.aspx</guid>
            <pubDate>Thu, 10 Apr 2008 23:37:38 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/121177.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/04/10/121177.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/121177.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/121177.aspx</trackback:ping>
        </item>
        <item>
            <title>Relooking at xUnit.net RC2</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/04/04/121048.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;UPDATE: More posts on the subject&lt;br /&gt;
&lt;/span&gt;
&lt;ul&gt;
    &lt;li style="font-weight: bold;"&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/04/10/xunit-net-rc3-just-released.aspx"&gt;xUnit.net RC3 Just Released&lt;/a&gt;&lt;br /&gt;
    &lt;/li&gt;
&lt;/ul&gt;
Earlier this week, I wrote about the latest release of xUnit.net RC2.  Since that time, &lt;a href="http://bradwilson.typepad.com/"&gt;Brad Wilson&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/jamesnewkirk/"&gt;Jim Newkirk&lt;/a&gt; released a new version to fix some of the issues with regards to &lt;a href="http://www.testdriven.net/"&gt;TestDriven.NET&lt;/a&gt; integration and &lt;a href="http://asp.net/mvc/"&gt;ASP.NET MVC&lt;/a&gt; integration.    You can read more about the issues &lt;a href="http://bradwilson.typepad.com/blog/2008/04/xunitnet-rc2--1.html"&gt;here&lt;/a&gt;.  As always you can get the latest bits &lt;a href="http://www.codeplex.com/xunit/Release/ProjectReleases.aspx?ReleaseId=12209"&gt;here&lt;/a&gt;.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;The Installer&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If you browse to the releases page of xUnit.net, you will notice an installer.  This installer will help integrate xUnit.net with &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper 3.1&lt;/a&gt; for Visual Studio 2005 and 2008, TestDriven.NET and ASP.NET MVC.  Just click the installer and a screen like below will show.  Note that I have &lt;a href="http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds"&gt;Resharper 4.0 nightly builds&lt;/a&gt; instead of 3.1, so those features aren't activated just yet, unfortunately.  &lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="http://weblogs.asp.net/blogs/podwysocki/xunitnet_installer_aspnetmvc.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
Since I didn't have anything else but ASP.NET MVC Preview 2 installed, that's all I got enabled.  It only takes a few seconds to enable.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;ASP.NET MVC&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now that I got the ASP.NET MVC plugin installed for xUnit, I can go ahead and open Visual Studio 2008 and create a new ASP.NET MVC application.  When it automatically creates the test project for me, I have the option now of using xUnit.net instead of that lesser one that came in here by default.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://weblogs.asp.net/blogs/podwysocki/aspnet_mvc_xunittests.png" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
Once I do that, it will create some tests of the HomeController and Routes by default as noted below:&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="http://weblogs.asp.net/blogs/podwysocki/aspnet_mvc_solution.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
But in order for this to work out of the box, there is some work you need to do.  Your tests will not compile by default because you need to change the namespace includes on top to include your application's namespace.  Not a huge issue mind you, but a little more work than usual.  Here's what it will look like:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red0\green255\blue0;\red255\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  MVC_APPLICATION_NAMESPACE.Controllers; \cf4 // This using directive needs to point to the namespace of your MVC project\par ??\cf1 using\cf3  Xunit;\par ??\par ??\cf1 namespace\cf3  PetShopTests.Controllers\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf5 HomeControllerFacts\par ??\cf3     \{\par ??        \cf1 public\cf3  \cf1 class\cf3  \cf5 Index\par ??\cf3         \{\par ??            [\cf5 Fact\cf3 ]\par ??            \cf1 public\cf3  \cf1 void\cf3  RendersTheIndexView()\par ??            \{\par ??                \cf5 TestableHomeController\cf3  controller = \cf1 new\cf3  \cf5 TestableHomeController\cf3 ();\par ??\par ??                controller.Index();\par ??\par ??                \cf5 Assert\cf3 .Equal(\cf4 "Index"\cf3 , controller.RenderView_ViewName);\par ??            \}\par ??        \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; MVC_APPLICATION_NAMESPACE.Controllers; &lt;span style="color: lime;"&gt;// This using directive needs to point to the namespace of your MVC project&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Xunit;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; PetShopTests.Controllers&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;HomeControllerFacts&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Index&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            [&lt;span style="color: yellow;"&gt;Fact&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; RendersTheIndexView()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;TestableHomeController&lt;/span&gt; controller = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;TestableHomeController&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                controller.Index();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: lime;"&gt;"Index"&lt;/span&gt;, controller.RenderView_ViewName);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
So, all you need to do is replace the &lt;span style="font-weight: bold;"&gt;MVC_APPLICATION_NAMESPACE&lt;/span&gt; with your own namespace and problem solved!  But out of the box, you have some working unit tests and some good guidance on how to get started.  If you're curious on how the integration actually works, check out this post &lt;a href="http://blogs.msdn.com/webdevtools/archive/2008/03/06/asp-net-mvc-test-framework-integration-demo.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;GUI Runner&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As Brad had stated earlier, there is a simple, yet effective GUI runner for xUnit.net.  So far there's not much to it, other than to load an assembly and run all associated tests.  To give you an example, I wrote some F# code and now I want to run some tests against it.  So, here is the code I used for these simple tests.  Yes, you can go ahead and yell at me for doing OO things in a functional language, but it's here to prove a point that you can.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;}??\fs16 \cf1\cb2\highlight2 #light\par ??\par ??\cf3 let\cf1  \cf3 rec\cf1  fib n = \par ??  \cf3 match\cf1  n \cf3 with\par ??\cf1   | 0 \cf3 -&amp;gt;\cf1  1\par ??  | 1 \cf3 -&amp;gt;\cf1  1\par ??  | x \cf3 -&amp;gt;\cf1  fib(n - 2) + fib(n - 1)\par ??  \par ??print_any (fib (-1))}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;#light&lt;br /&gt;
&lt;br /&gt;
#R @&lt;span style="color: rgb(0, 255, 0);"&gt;"E:\Tools\xunit-build-1223-samples\Samples\xunit\xunit.dll" &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;System&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;System.Collections.Generic&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;Xunit&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;type &lt;/span&gt;Stack&amp;lt;'t&amp;gt; = &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt;&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;val&lt;/span&gt; elements : LinkedList&amp;lt;'t&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  new() = { elements = &lt;span style="color: rgb(255, 128, 0);"&gt;new &lt;/span&gt;LinkedList&amp;lt;'t&amp;gt;() }&lt;br /&gt;
  &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.IsEmpty&lt;br /&gt;
    &lt;span style="color: rgb(255, 128, 0);"&gt;with &lt;/span&gt;get() = x.elements.Count = 0&lt;br /&gt;
    &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.Push element =&lt;br /&gt;
    x.elements.AddFirst(element:'t)&lt;br /&gt;
    &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.Top&lt;br /&gt;
    &lt;span style="color: rgb(255, 128, 0);"&gt;with &lt;/span&gt;get() =&lt;br /&gt;
      &lt;span style="color: rgb(255, 128, 0);"&gt;if &lt;/span&gt;x.elements.Count = 0 &lt;span style="color: rgb(255, 128, 0);"&gt;then&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
        raise (InvalidOperationException(&lt;span style="color: rgb(0, 255, 0);"&gt;"cannot top an empty stack"&lt;/span&gt;))&lt;br /&gt;
      x.elements.First.Value&lt;br /&gt;
      &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.Pop = &lt;br /&gt;
    &lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;top = x.Top&lt;br /&gt;
    x.elements.RemoveFirst()&lt;br /&gt;
    top&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
[&amp;lt;Fact&amp;gt;]   &lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;NoElementsShouldBeEmpty () =&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;stack = new Stack&amp;lt;string&amp;gt;()&lt;br /&gt;
  Assert.True(stack.IsEmpty)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;[&amp;lt;Fact&amp;gt;]&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;PushAnElementShouldNotBeEmpty() =&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;stack = new Stack&amp;lt;string&amp;gt;()&lt;br /&gt;
  stack.Push(&lt;span style="color: rgb(0, 255, 0);"&gt;"first element"&lt;/span&gt;)&lt;br /&gt;
  Assert.False(stack.IsEmpty)&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And now, open the xunit.gui.exe and select your assembly you want to run.  I chose my fsharpsamples.dll that I've been working with on my F# samples.  Now, let's give these two tests a run to see how they do.&lt;br /&gt;
&lt;br /&gt;
&lt;img src="http://weblogs.asp.net/blogs/podwysocki/xunitnet_guirunner_greenlight.png" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, not much information is given to me other than the number of passed tests, the time taken and my assembly under test.  Not much information, but enough to get started.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, a bit of progress has been made on xUnit.net and here's hoping the version 1.0 full release is coming soon.  As I look at it more and more, I'm definitely starting to like it.  I haven't had to create as many extensions as I would have to do with MSTest such as Assert.Throws&amp;lt;T&amp;gt; and so on.  So, I encourage you to go ahead and once again, give it a look and give feedback to the team.  Until next time... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/04/121048.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/04/121048.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121048"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121048" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/121048.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/04/04/121048.aspx</guid>
            <pubDate>Fri, 04 Apr 2008 23:34:24 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/121048.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/04/04/121048.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/121048.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/121048.aspx</trackback:ping>
        </item>
        <item>
            <title>Covering NUnit 2.4.7</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/04/01/120934.aspx</link>
            <description>It's interesting that a flurry of releases of testing frameworks have been released lately with &lt;a href="http://www.gallio.org/"&gt;Gallio&lt;/a&gt;, &lt;a href="http://codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; and of course &lt;a href="http://nunit.com/index.php"&gt;NUnit&lt;/a&gt;.&lt;a href="http://blogs.nunit.com/"&gt;  Charlie Poole&lt;/a&gt; recently announced on a lot of the discussion boards I belong to recently that &lt;a href="http://nunit.com/index.php?p=download"&gt;NUnit 2.4.7&lt;/a&gt; was recently released.  You can read all about what's been added &lt;a href="http://nunit.com/index.php?p=releaseNotes&amp;amp;r=2.4.7"&gt;here &lt;/a&gt;with the release notes.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;What's New and Interesting?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
What's interesting about this release?  Well, NUnit no longer depends on log4net, thus getting rid of some dependency issues with regards to the applications under test.  What's also interesting is that addition of the RowTest extension to allow  multiple sets of arguments to be given to a test.  This is the first one that's ever been incorporated into the core of NUnit.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Static Tests in NUnit?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As &lt;a href="http://weblogs.asp.net/astopford/"&gt;Andy Stopford&lt;/a&gt; noted in my blog yesterday regarding xUnit.net, &lt;a href="http://sourceforge.net/mailarchive/forum.php?thread_name=004401c887ad%249e816030%246501a8c0%40ferrari&amp;amp;forum_name=nunit-developer"&gt;Charlie recently checked in code&lt;/a&gt; to allow static methods for static methods to be tests as well as Setup and TearDown to be static as well.  Jim Newkirk, the man behind NUnit and co-creator of xUnit.net, favors that approach of allowing statics.  To me, I don't care as much with regards to Startup and TearDown with statics as most of my statics for testing F# is side effect free programming.  As it should be with functional programming.  Anyhow, what I'd like to see in NUnit is the support for something that I can do in xUnit.net:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;}??\fs16 \cf1\cb2\highlight2 #light\par ??\par ??\cf3 let\cf1  \cf3 rec\cf1  fib n = \par ??  \cf3 match\cf1  n \cf3 with\par ??\cf1   | 0 \cf3 -&amp;gt;\cf1  1\par ??  | 1 \cf3 -&amp;gt;\cf1  1\par ??  | x \cf3 -&amp;gt;\cf1  fib(n - 2) + fib(n - 1)\par ??  \par ??print_any (fib (-1))}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;#light&lt;br /&gt;
&lt;br /&gt;
#R &lt;span style="color: rgb(0, 255, 0);"&gt;@"D:\Program Files\NUnit 2.4.7\bin\nunit.core.dll"&lt;/span&gt;&lt;br /&gt;
#R &lt;span style="color: rgb(0, 255, 0);"&gt;@"D:\Program Files\NUnit 2.4.7\bin\nunit.framework.dll"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;NUnit.Framework&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;rec&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;fib n =&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;match&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;n &lt;span style="color: rgb(255, 128, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;with&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
  | 0 | 1 &lt;span style="color: rgb(255, 128, 0);"&gt;-&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;/span&gt; 0&lt;br /&gt;
  | n &lt;span style="color: rgb(255, 128, 0);"&gt;-&amp;gt;&lt;/span&gt; fib(n-2) + fib(n-1)&lt;br /&gt;
  | n &lt;span style="color: rgb(255, 128, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;when&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt; n &amp;lt; 0 &lt;span style="color: rgb(255, 128, 0);"&gt;-&amp;gt;&lt;/span&gt; failwith &lt;span style="color: rgb(0, 255, 0);"&gt;"Cannot be less than zero"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
[&amp;lt;TestFixture&amp;gt;]&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;/span&gt;FibOfOneShouldReturnZero() =&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;/span&gt;fibResult = fib(1)&lt;br /&gt;
  Assert.AreEqual(fibResult, 0)&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
If I saw something like this, I'd be a happy man.  But until then, I can dream...&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Go ahead and pick up your copy today of NUnit.  It's been the old standby for many of my projects throughout my career and served me quite well.  Next time I'll cover Gallio a little bit as I have neglected it, but it's a huge release.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/01/120934.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/01/120934.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120934"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120934" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120934.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/04/01/120934.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 22:34:37 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120934.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/04/01/120934.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120934.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120934.aspx</trackback:ping>
        </item>
        <item>
            <title>XUnit.net RC2 Released</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/31/120904.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;UPDATE: More posts on the subject&lt;br /&gt;
&lt;/span&gt;
&lt;ul&gt;
    &lt;li style="font-weight: bold;"&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/04/10/xunit-net-rc3-just-released.aspx"&gt;xUnit.net RC3 Just Released&lt;/a&gt;&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/04/04/relooking-at-xunit-net-rc2.aspx" style="font-weight: bold;"&gt;Relooking at xUnit.net RC2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;
UPDATE: xUnit.NET RC2 New Drop includes ASP.NET MVC support and better GUI runner.  Details &lt;a href="http://bradwilson.typepad.com/blog/2008/04/xunitnet-rc2--1.html"&gt;here&lt;/a&gt;.&lt;br /&gt;
UPDATE: Added Static Methods mention and F# - Thanks to &lt;a href="http://devhawk.net"&gt;DevHawk&lt;/a&gt;!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I've been a big fan of such testing frameworks as &lt;a href="http://www.nunit.org/"&gt;NUnit&lt;/a&gt; and &lt;a href="http://www.mbunit.com/"&gt;MbUnit&lt;/a&gt;, but recently I've found myself getting pulled more towards &lt;a href="http://codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; at least to play around with for any of my code samples that I write for this blog and on my own time.  I'm not really a fan of MSTest and many I think would agree about its deficiencies.  I won't go as far as say &lt;a href="http://jayflowers.com/joomla/"&gt;Jay Flowers&lt;/a&gt; and wear the shirt though...&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Another Release?&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;
&lt;br /&gt;
Recently, &lt;a href="http://bradwilson.typepad.com/"&gt;Brad Wilson&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/jamesnewkirk/default.aspx"&gt;Jim Newkirk&lt;/a&gt; recently announced the release of &lt;a href="http://codeplex.com/xunit"&gt;xUnit.net RC2&lt;/a&gt; on CodePlex.  I'd encourage you download the latest bits &lt;a href="http://www.codeplex.com/xunit/Release/ProjectReleases.aspx?ReleaseId=9681"&gt;here&lt;/a&gt;.  For those wondering what changes happened between RC1 and RC2, Brad has a good writeup on his blog &lt;a href="http://bradwilson.typepad.com/blog/2008/03/xunitnet-10-rc2.html"&gt;here&lt;/a&gt;.  What's interesting about this is the removal of the Assert class methods which take a user defined message should it fail.  I was never really a fan of those in the first place though.  &lt;br /&gt;
&lt;br /&gt;
Another interesting added features was the IUserFixture&amp;lt;T&amp;gt; which allows you to have a startup and teardown for your fixtures in a separate class and therefore reusable, unlike the current way of using no parameter constructors as your startup and the IDisposable.Dispose for your teardown.  See the tests in the FixtureExample for details.  But here's a snipped version of that code:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;\red163\green21\blue21;}??\fs16 \cf1\cb2\highlight2     \cf3 public\cf1  \cf3 class\cf1  \cf4 DatabaseFixture\cf1  : \cf5 IDisposable\par ??\cf1     \{\par ??        \cf4 SqlConnection\cf1  connection;\par ??        \cf3 int\cf1  fooUserID;\par ??\par ??        \cf3 public\cf1  DatabaseFixture()\par ??        \{\par ??            \cf3 string\cf1  connectionString = \cf4 ConfigurationManager\cf1 .ConnectionStrings[\cf6 "DatabaseFixture"\cf1 ].ConnectionString;\par ??            connection = \cf3 new\cf1  \cf4 SqlConnection\cf1 (connectionString);\par ??            connection.Open();\par ??\par ??            \cf3 string\cf1  sql = \cf7 @"INSERT INTO Users VALUES ('foo', 'bar'); SELECT SCOPE_IDENTITY();"\cf1 ;\par ??\par ??            \cf3 using\cf1  (\cf4 SqlCommand\cf1  cmd = \cf3 new\cf1  \cf4 SqlCommand\cf1 (sql, connection))\par ??                fooUserID = \cf4 Convert\cf1 .ToInt32(cmd.ExecuteScalar());\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf4 SqlConnection\cf1  Connection\par ??        \{\par ??            \cf3 get\cf1  \{ \cf3 return\cf1  connection; \}\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 int\cf1  FooUserID\par ??        \{\par ??            \cf3 get\cf1  \{ \cf3 return\cf1  fooUserID; \}\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  Dispose()\par ??        \{\par ??            \cf3 string\cf1  sql = \cf7 @"DELETE FROM Users WHERE ID = @id;"\cf1 ;\par ??\par ??            \cf3 using\cf1  (\cf4 SqlCommand\cf1  cmd = \cf3 new\cf1  \cf4 SqlCommand\cf1 (sql, connection))\par ??            \{\par ??                cmd.Parameters.AddWithValue(\cf6 "@id"\cf1 , fooUserID);\par ??                cmd.ExecuteNonQuery();\par ??            \}\par ??\par ??            connection.Close();\par ??        \}\par ??    \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;DatabaseFixture&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IDisposable&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: yellow;"&gt;SqlConnection&lt;/span&gt; connection;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;int&lt;/span&gt; fooUserID;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; DatabaseFixture()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; connectionString = &lt;span style="color: yellow;"&gt;ConfigurationManager&lt;/span&gt;.ConnectionStrings[&lt;span style="color: lime;"&gt;"DatabaseFixture"&lt;/span&gt;].ConnectionString;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            connection = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;SqlConnection&lt;/span&gt;(connectionString);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            connection.Open();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; sql = &lt;span style="color: rgb(163, 21, 21);"&gt;@"INSERT INTO Users VALUES ('foo', 'bar'); SELECT SCOPE_IDENTITY();"&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; (&lt;span style="color: yellow;"&gt;SqlCommand&lt;/span&gt; cmd = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;SqlCommand&lt;/span&gt;(sql, connection))&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                fooUserID = &lt;span style="color: yellow;"&gt;Convert&lt;/span&gt;.ToInt32(cmd.ExecuteScalar());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: yellow;"&gt;SqlConnection&lt;/span&gt; Connection&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; connection; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;int&lt;/span&gt; FooUserID&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; fooUserID; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Dispose()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; sql = &lt;span style="color: rgb(163, 21, 21);"&gt;@"DELETE FROM Users WHERE ID = @id;"&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; (&lt;span style="color: yellow;"&gt;SqlCommand&lt;/span&gt; cmd = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;SqlCommand&lt;/span&gt;(sql, connection))&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                cmd.Parameters.AddWithValue(&lt;span style="color: lime;"&gt;"@id"&lt;/span&gt;, fooUserID);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                cmd.ExecuteNonQuery();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            connection.Close();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
What the above code allows us to do is to define a class that holds the data from the initialization of the first test, to the cleanup after the last test.  Our state is therefore maintained in a reusable manner.  As you will note, the startup logic resides in the default no parameter constructor and all teardown logic is in the IDisposable.Dispose method.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2     \cf3 public\cf1  \cf3 class\cf1  \cf4 FixtureTests\cf1  : \cf5 IUseFixture\cf1 &amp;lt;\cf4 DatabaseFixture\cf1 &amp;gt;\par ??    \{\par ??        \cf4 DatabaseFixture\cf1  database;\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  SetFixture(\cf4 DatabaseFixture\cf1  data)\par ??        \{\par ??            database = data;\par ??        \}\par ??\par ??        [\cf4 Fact\cf1 ]\par ??        \cf3 public\cf1  \cf3 void\cf1  ConnectionIsEstablished()\par ??        \{\par ??            \cf4 Assert\cf1 .NotNull(database.Connection);\par ??        \}\par ??\par ??        [\cf4 Fact\cf1 ]\par ??        \cf3 public\cf1  \cf3 void\cf1  FooUserWasInserted()\par ??        \{\par ??            \cf3 string\cf1  sql = \cf6 "SELECT COUNT(*) FROM Users WHERE ID = @id;"\cf1 ;\par ??\par ??            \cf3 using\cf1  (\cf4 SqlCommand\cf1  cmd = \cf3 new\cf1  \cf4 SqlCommand\cf1 (sql, database.Connection))\par ??            \{\par ??                cmd.Parameters.AddWithValue(\cf6 "@id"\cf1 , database.FooUserID);\par ??\par ??                \cf3 int\cf1  rowCount = \cf4 Convert\cf1 .ToInt32(cmd.ExecuteScalar());\par ??\par ??                \cf4 Assert\cf1 .Equal(1, rowCount);\par ??            \}\par ??        \}\par ??    \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;FixtureTests&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IUseFixture&lt;/span&gt;&amp;lt;&lt;span style="color: yellow;"&gt;DatabaseFixture&lt;/span&gt;&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: yellow;"&gt;DatabaseFixture&lt;/span&gt; database;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; SetFixture(&lt;span style="color: yellow;"&gt;DatabaseFixture&lt;/span&gt; data)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            database = data;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;   &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        [&lt;span style="color: yellow;"&gt;Fact&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; FooUserWasInserted()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; sql = &lt;span style="color: lime;"&gt;"SELECT COUNT(*) FROM Users WHERE ID = @id;"&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; (&lt;span style="color: yellow;"&gt;SqlCommand&lt;/span&gt; cmd = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;SqlCommand&lt;/span&gt;(sql, database.Connection))&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                cmd.Parameters.AddWithValue(&lt;span style="color: lime;"&gt;"@id"&lt;/span&gt;, database.FooUserID);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;int&lt;/span&gt; rowCount = &lt;span style="color: yellow;"&gt;Convert&lt;/span&gt;.ToInt32(cmd.ExecuteScalar());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(1, rowCount);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Then we can go ahead with our tests, while using the SqlConnection as defined on our DatabaseFixture.  After we're done with our test, it goes ahead and calls Dispose on the fixture.  I tend to like this approach and it's definitely growing on me.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Why xUnit.net?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
For those new to xUnit.net, there are some decent links to help you along.  Some of the more interesting ones can be found here:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://www.codeplex.com/xunit/Wiki/View.aspx?title=Comparisons&amp;amp;referringTitle=Home"&gt;Comparison to MbUnit, NUnit and MSTest&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.codeplex.com/xunit/Wiki/View.aspx?title=HowToUseResharper&amp;amp;referringTitle=Home"&gt;Running Resharper with xUnit.net&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blog.benhall.me.uk/2008/01/introduction-to-xunit.html"&gt;An introduction to xUnit.net&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blog.benhall.me.uk/2008/01/introduction-to-xunitnet-extensions.html"&gt;An introduction to xUnit.net extensions&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blog.benhall.me.uk/2008/01/creating-your-own-xunit-extension.html"&gt;Create your own xUnit.net extension&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
But, why am I interested in it?  Well, let's just say that I think it tackles things in a slightly different manner.  I think one of the key pieces that I really like is the Assert.Throws instead of the clumsy ExpectedExceptionAttribute which you must clutter your tests with on the top.  I would rather assert that such a thing happened programmatically, so that I may analyze the exception.  I can also specify which line I expect during my test will throw the exception, instead of taking on blind faith that my test threw an exception.  It may be of the right type, but that may not have been the one you wanted, thus giving a false sense of security.&lt;br /&gt;
&lt;br /&gt;
To use this, just simply use the Assert.Throws&amp;lt;TException&amp;gt;(Assert.ThrowsDelegate) which I've found to be very helpful.  Let's look at a quick test of that being used.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green255\blue0;\red255\green128\blue0;}??\fs16 \cf1\cb2\highlight2     [\cf3 Fact\cf1 ]\par ??    \cf4 public\cf1  \cf4 void\cf1  PopEmptyStack()\par ??    \{\par ??        \cf3 Stack\cf1 &amp;lt;\cf4 string\cf1 &amp;gt; stack = \cf4 new\cf1  \cf3 Stack\cf1 &amp;lt;\cf4 string\cf1 &amp;gt;();\par ??        \cf3 Assert\cf1 .Throws&amp;lt;\cf3 InvalidOperationException\cf1 &amp;gt;(() =&amp;gt; stack.Pop());\par ??    \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;    [&lt;span style="color: yellow;"&gt;Fact&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; PopEmptyStack()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: yellow;"&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;&amp;gt; stack = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;Stack&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Throws&amp;lt;&lt;span style="color: yellow;"&gt;InvalidOperationException&lt;/span&gt;&amp;gt;(() =&amp;gt; stack.Pop());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
As you can see, we're pretty explicit about what line will throw the exception, and that's really the key to this scenario.  There are a good number of samples provided on the releases page that you should check out.  As always with most products that I talk about, I highly recommend reading the tests to really fully understand what's going on underneath the covers.  Not only does it help you understand the intent of the program, but you can learn about good coding techniques, design patterns, testing patterns and so on.&lt;br /&gt;
&lt;br /&gt;
Another point that xUnit.net separates itself from the pack is the ability to decorate static methods as facts.  This frees you from having to create an instance of your test class in order to call them.  Harry Pierson, aka DevHawk, demonstrates its use with regards to F# and testing the parse buffer &lt;a href="http://devhawk.net/2007/12/12/Practical+F+Parsing+Unit+Testing.aspx"&gt;here&lt;/a&gt;.  It definitely opened my eyes and a few more avenues as I pursue more F# related work items in the future.  Here's just a quick and dirty sample of showing how you can use xUnit.net with F# quite easily, just as Harry's post did.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;}??\fs16 \cf1\cb2\highlight2 #light\par ??\par ??\cf3 let\cf1  \cf3 rec\cf1  fib n = \par ??  \cf3 match\cf1  n \cf3 with\par ??\cf1   | 0 \cf3 -&amp;gt;\cf1  1\par ??  | 1 \cf3 -&amp;gt;\cf1  1\par ??  | x \cf3 -&amp;gt;\cf1  fib(n - 2) + fib(n - 1)\par ??  \par ??print_any (fib (-1))}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;#light&lt;br /&gt;
&lt;br /&gt;
#R @&lt;span style="color: rgb(0, 255, 0);"&gt;"E:\Tools\xunit-build-1223-samples\Samples\xunit\xunit.dll" &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;System&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;System.Collections.Generic&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;open&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;Xunit&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;type &lt;/span&gt;Stack&amp;lt;'t&amp;gt; = &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt;&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;val&lt;/span&gt; elements : LinkedList&amp;lt;'t&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  new() = { elements = &lt;span style="color: rgb(255, 128, 0);"&gt;new &lt;/span&gt;LinkedList&amp;lt;'t&amp;gt;() }&lt;br /&gt;
  &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.IsEmpty&lt;br /&gt;
    &lt;span style="color: rgb(255, 128, 0);"&gt;with &lt;/span&gt;get() = x.elements.Count = 0&lt;br /&gt;
    &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.Push element =&lt;br /&gt;
    x.elements.AddFirst(element:'t)&lt;br /&gt;
    &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.Top&lt;br /&gt;
    &lt;span style="color: rgb(255, 128, 0);"&gt;with &lt;/span&gt;get() =&lt;br /&gt;
      &lt;span style="color: rgb(255, 128, 0);"&gt;if &lt;/span&gt;x.elements.Count = 0 &lt;span style="color: rgb(255, 128, 0);"&gt;then&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
        raise (InvalidOperationException(&lt;span style="color: rgb(0, 255, 0);"&gt;"cannot top an empty stack"&lt;/span&gt;))&lt;br /&gt;
      x.elements.First.Value&lt;br /&gt;
      &lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;member&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;x.Pop = &lt;br /&gt;
    &lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;top = x.Top&lt;br /&gt;
    x.elements.RemoveFirst()&lt;br /&gt;
    top&lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
[&amp;lt;Fact&amp;gt;]   &lt;br /&gt;
&lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;NoElementsShouldBeEmpty () =&lt;br /&gt;
  &lt;span style="color: rgb(255, 128, 0);"&gt;let&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;stack = new Stack&amp;lt;string&amp;gt;()&lt;br /&gt;
  Assert.True(stack.IsEmpty)&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
If you notice, the FactAttribute is placed on a static method called NoElementsShouldBeEmpty and sure enough it works like a champ through xUnit.net.  I like this approach instead of the pomp and circumstance required for creating classes as shown above with my Stack class.  Note the use of the empty parans which forces it to be a void method with no values passed either.  But if you run it through the xunit.console sure enough it succeeds like a champ.&lt;br /&gt;
&lt;br /&gt;
What are we missing though?  Well, I'm in favor of having a standalone GUI Test Runner much like NUnit and MbUnit have.  In fact, Brad has started this and you can get these features from the latest commits &lt;a href="http://www.codeplex.com/xunit/SourceControl/ListDownloadableCommits.aspx"&gt;here&lt;/a&gt;.  Mind you I haven't gotten it to work just right yet, but it's a work in progress.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
There is a lot to like about xUnit.net and takes a lot of lessons learned from the use of NUnit, MbUnit and others and I think they're doing a good job incorporating issues.  This project isn't as active as MbUnit and NUnit, but it's definitely one to keep an eye on.  Recent releases of NUnit and Gallio Automation Platform will probably be also covered in the short while as well as they have a lot to offer.  Until next time... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/31/120904.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/31/120904.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120904"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120904" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120904.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/31/120904.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 00:31:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120904.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/31/120904.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120904.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120904.aspx</trackback:ping>
        </item>
        <item>
            <title>IoC and Unity - The Basics and InterceptionIoC and Unity - The Basics and Interception</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/26/120764.aspx</link>
            <description>I realize it's been a while since my last post on &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control"&gt;Inversion of Control&lt;/a&gt; containers and looking at Unity as one of them.  Since that time, &lt;a href="http://www.hanselman.com/blog/" mce_href="http://www.hanselman.com/blog/"&gt;Scott Hanselman&lt;/a&gt; linked to some of the comparisons that I did for IoC containers &lt;a href="http://www.hanselman.com/blog/ListOfNETDependencyInjectionContainersIOC.aspx" mce_href="http://www.hanselman.com/blog/ListOfNETDependencyInjectionContainersIOC.aspx"&gt;here&lt;/a&gt;.  I'll be the first to admit that the look was a bit naive, but to get you all interested in looking at IoC container and how they can improve your applications.  It was suggested &lt;a href="http://www.ayende.com/Blog/archive/2008/03/14/Evaluating-IoC-containers.aspx" mce_href="http://www.ayende.com/Blog/archive/2008/03/14/Evaluating-IoC-containers.aspx"&gt;here &lt;/a&gt;that my posts weren't a complete comparison, although in my previous posts I covered a lot of those topics.  Even so, after talking with &lt;a href="http://www.ayende.com/"&gt;said individual&lt;/a&gt;, I need to cover more ground on the basics and dive deeper into the details.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Where We Are&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Before we begin today, let's see what we've already covered in the past:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/07/ioc-container-unity-and-breaking-changes-galore.aspx"&gt;IoC Container, Unity and Breaking Changes Galore&lt;/a&gt;&lt;br /&gt;
    Covers the breaking changes made from the old Unity drop to the new one&lt;br /&gt;
    &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/04/ioc-containers-unity-and-objectbuilder2-the-saga-continues.aspx"&gt;&lt;br /&gt;
    &lt;/a&gt;     &lt;/li&gt;
    &lt;li&gt;&lt;a href="javascript:void(0);/*1206509408817*/"&gt;IoC Containers, Unity and ObjectBuilder2 - The Saga Continues&lt;/a&gt;&lt;br /&gt;
    Managing instances and parameter mapping resolution&lt;br /&gt;
    &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx"&gt;&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/02/26/ioc-and-the-unity-application-block-once-again.aspx"&gt;IoC and the Unity Application Block Once Again&lt;/a&gt;&lt;br /&gt;
    Setter Injection versus Constructor Injection and PostSharp4Unity&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/02/22/ioc-and-the-unity-application-block-going-deeper.aspx"&gt;IoC and the Unity Application Block - Going Deeper&lt;/a&gt;&lt;br /&gt;
    Constructor Injection and comparing Unity with Castle Windsor&lt;br /&gt;
    &lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/02/18/ioc-and-the-unity-application-block.aspx"&gt;IoC and the Unity Application Block&lt;/a&gt;&lt;br /&gt;
    Covering ObjectBuilder and Unity Application Block&lt;/li&gt;
&lt;/ul&gt;
So, we have a bit of back history, but I think I dived too far into things without giving some of the back story.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; DI Frameworks Galore&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As Scott Hanselman noted, there are a number of IoC containers in the .NET Space.  Most of these I was already aware of and played with, so I'm only going to list the ones I've played with.  Here they are in no particular order:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://www.castleproject.org/container/index.html"&gt;Castle Windsor&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://structuremap.sourceforge.net/"&gt;StructureMap&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.springframework.net/"&gt;Spring.NET&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.codeplex.com/ObjectBuilder/SourceControl/DownloadSourceCode.aspx?changeSetId=29957"&gt;ObjectBuilder2 CodePlex Container&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://codeplex.com/unity"&gt;Unity Application Block&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.codeproject.com/KB/cs/LinFuPart1.aspx"&gt;LinFu&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://ninject.org/"&gt;NInject&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://code.google.com/p/autofac/"&gt;AutoFac&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.puzzleframework.com/"&gt;Puzzle.NET&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://s2container.net.seasar.org/en/index.html"&gt;S2Container.NET&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
So, as you can see, there are plenty to choose from.  They all serve basic IoC needs and I'll talk about that a little bit more later.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Getting Back to Basics&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When we talk about Inversion of Control and &lt;a href="http://en.wikipedia.org/wiki/Dependency_inversion_principle"&gt;dependency inversion principle&lt;/a&gt;, we're talking about loosely coupled applications.  It follows the &lt;a href="http://en.wikipedia.org/wiki/Hollywood_Principle"&gt;Hollywood Principle&lt;/a&gt; which is the trite "Don't call use, we'll call you" mantra.  In a way it means that those dependencies that you have inside your class, say your Logger and its associated formatter.  In the tightly coupled world, you would have a private member of a Logger.  Instead, what you would have in the other case is an interface or abstract class that would represent the functionality of that logger, and that instance given to your class.  Throw on top of that a container to manage those dependencies to those interfaces and mappings to concrete classes.  Also, your container can manage the object lifetimes as well.   &lt;a href="http://www.ayende.com/"&gt;Ayende&lt;/a&gt; shows how easy it is to &lt;a href="http://www.ayende.com/Blog/archive/2007/10/20/Building-an-IoC-container-in-15-lines-of-code.aspx"&gt;create a simple container&lt;/a&gt;, although it misses an important point about lifetime management.&lt;br /&gt;
&lt;br /&gt;
To put it succinctly, to be a container should satisfy the following requirements:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Configuration - Registering types and mappings through code, XML or script&lt;br /&gt;
    &lt;/li&gt;
    &lt;li&gt;Lifetime Management - How the lifetime of the objects are managed, singleton, transient, etc&lt;/li&gt;
    &lt;li&gt;Resolution - Resolve dependencies and instantiate&lt;/li&gt;
    &lt;li&gt;Extensibility - Be able to add new facilities for additional features (interception, AOP, and so on)&lt;/li&gt;
&lt;/ul&gt;
Before we get into any advanced topics, let's get into more detail.  &lt;a href="http://codebetter.com/blogs/james.kovacs/default.aspx"&gt;James Kovacs&lt;/a&gt; wrote in the March 2008 edition of MSDN Magazine called &lt;a href="http://msdn2.microsoft.com/en-ca/magazine/cc337885.aspx"&gt;"Loosen Up - Tame Your Software Dependencies For More Flexible Apps"&lt;/a&gt;.   This article is a great start for those trying to understand dependency inversion and dependency injection.  James walks through a simple application with tight coupling, and then works to loosen it.  Once that is complete, Castle Windsor is introduced and walks through the XML configuration or using Binsor to auto-wire the container.&lt;br /&gt;
&lt;br /&gt;
One of the more key points in this article and it came from Ayende is to have an anti-corruption layer for your IoC container.  Yes, that's the same Domain Driven Design term in which we isolate things that don't conform to our given architecture and can translate from one context to another.  Let's throw up a simple example of using this.  Remember it's just a quick spike of an anti-corruption layer.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 static\cf3  \cf1 class\cf3  \cf4 IoC\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 static\cf3  \cf5 IDependencyResolver\cf3  resolver;\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  \cf1 void\cf3  Initialize(\cf5 IDependencyResolver\cf3  resolver)\par ??        \{\par ??            \cf4 IoC\cf3 .resolver = resolver;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;()\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;();\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 static\cf3  T Resolve&amp;lt;T&amp;gt;(\cf1 string\cf3  name)\par ??        \{\par ??            \cf1 return\cf3  resolver.Resolve&amp;lt;T&amp;gt;(name);\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;IoC&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDependencyResolver&lt;/span&gt; resolver;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Initialize(&lt;span style="color: rgb(43, 145, 175);"&gt;IDependencyResolver&lt;/span&gt; resolver)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;IoC&lt;/span&gt;.resolver = resolver;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; T Resolve&amp;lt;T&amp;gt;()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; resolver.Resolve&amp;lt;T&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; T Resolve&amp;lt;T&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; name)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; resolver.Resolve&amp;lt;T&amp;gt;(name);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
So, what we have is an IDependencyResolver given to the singleton IoC container.  Like I said, this isn't best practice as I haven't done any checking on whether the resolver was initialized or not.  But, what we want is to expose the way of resolving dependencies.  Now let's take a look at the IDependencyResolver interface and how that's used.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 interface\cf3  \cf4 IDependencyResolver\par ??\cf3     \{\par ??        T Resolve&amp;lt;T&amp;gt;(\cf1 string\cf3  name);\par ??\par ??        T Resolve&amp;lt;T&amp;gt;();\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IDependencyResolver&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        T Resolve&amp;lt;T&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; name);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        T Resolve&amp;lt;T&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Not much to this but gives us the ability to resolve our dependencies by type, or by type and name.  Pretty simple code here once again.  But, if I wanted to suddenly use Unity as the backing store, I'd simply implement it as the following:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  System.Configuration;\par ??\cf1 using\cf3  Microsoft.Practices.Unity;\par ??\cf1 using\cf3  Microsoft.Practices.Unity.Configuration;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 UnityDependencyResolver\cf3 : \cf5 IDependencyResolver\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf5 IUnityContainer\cf3  container;\par ??\par ??        \cf1 public\cf3  UnityDependencyResolver()\par ??        \{\par ??            container = \cf1 new\cf3  \cf4 UnityContainer\cf3 ();\par ??            \cf4 UnityConfigurationSection\cf3  section = (\cf4 UnityConfigurationSection\cf3 )\cf4 ConfigurationManager\cf3 .GetSection(\cf6 "unity"\cf3 );\par ??            section.Containers.Default.GetConfigCommand().Configure(container);\par ??        \}\par ??\par ??        \cf1 public\cf3  T Resolve&amp;lt;T&amp;gt;()\par ??        \{\par ??            \cf1 return\cf3  container.Resolve&amp;lt;T&amp;gt;();\par ??        \}\par ??\par ??        \cf1 public\cf3  T Resolve&amp;lt;T&amp;gt;(\cf1 string\cf3  name)\par ??        \{\par ??            \cf1 return\cf3  container.Resolve&amp;lt;T&amp;gt;(name);\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; System.Configuration;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity.Configuration;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityDependencyResolver&lt;/span&gt;: &lt;span style="color: rgb(43, 145, 175);"&gt;IDependencyResolver&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; container;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; UnityDependencyResolver()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;UnityConfigurationSection&lt;/span&gt; section = (&lt;span style="color: yellow;"&gt;UnityConfigurationSection&lt;/span&gt;)&lt;span style="color: yellow;"&gt;ConfigurationManager&lt;/span&gt;.GetSection(&lt;span style="color: lime;"&gt;"unity"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            section.Containers.Default.GetConfigCommand().Configure(container);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; T Resolve&amp;lt;T&amp;gt;()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; container.Resolve&amp;lt;T&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; T Resolve&amp;lt;T&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; name)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; container.Resolve&amp;lt;T&amp;gt;(name);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
So, all I'd have to do to switch from one container to another is just swap out the IDependencyResolver and I'm finished.  But, unfortunately, there are some techniques that are partial to one container or another, so there may be some things I'd lose there.  But for most cases, this pattern works and works well at that.&lt;br /&gt;
&lt;br /&gt;
Of course loose coupling, dependency injection and using IoC containers are nice in terms of making unit tests easier, but as you can see, there's a bit more to it than that, including the lifetime management, interception, the flexibility of changing implementations and so on.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Interception and Aspect Oriented Programming&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://en.wikipedia.org/wiki/Aspect_oriented_programming"&gt;Aspect Oriented Programming (AOP)&lt;/a&gt; and basic interception are interesting pieces of some containers.  This technique allows us to handle cross-cutting concerns such as logging, transaction management, security and so on at a different level instead of littering our code and domain model with checks everywhere.  Instead, we centralize those concerns and have them intercept calls and do their work.  Let's get some jargon straight here before we go any further.  An &lt;span style="font-weight: bold;"&gt;aspect &lt;/span&gt;is the part that encapsulates the cross-cutting concern such as logging.  These aspects can give advice, which is to alter the behavior of a given program.  The &lt;span style="font-weight: bold;"&gt;advice &lt;/span&gt;is given at certain &lt;span style="font-weight: bold;"&gt;join points&lt;/span&gt; which is where the aspect advice and the program intersect.  A group of these join points are called a &lt;span style="font-weight: bold;"&gt;pointcut&lt;/span&gt;. &lt;br /&gt;
&lt;br /&gt;
Interception is a feature of some of the IoC containers out there.  A few come to mind such as Castle Windsor, Spring.NET, LinFu, S2Container, Puzzle.NET and even ObjectBuilder2.  These containers provide at least a basic level of interception, meaning that you can intercept calls to methods, analyze the contents of the method call, proceed with the call and even modify the return value.  Since most containers support simple interception, I haven't found it more useful than logging or enforcing security on various things.  However, it can be extended to support more robust Policy Injection style of programming such as you would find in the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb410104.aspx"&gt;Policy Injection Application Block&lt;/a&gt;.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt; Interception in Unity?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Quite a bit has changed with Unity since I last blogged about it in terms of the configuration.  You can grab the latest bits &lt;a href="http://www.codeplex.com/unity/Release/ProjectReleases.aspx?ReleaseId=11956"&gt;here&lt;/a&gt;.  It would be nice to have changesets and such checked into CodePlex for things like this instead of zip files or MSIs, but oh well.  Anyhow, most of the changes revolve around managing lifetimes and handling the parameters for constructor injection.  You can read the tests and figure it out.&lt;br /&gt;
&lt;br /&gt;
As I've covered before, right now simple injection in Unity is not supported at the moment.  The intention is to have the Policy Injection Application Block fill that role.  There is also PostSharp4Unity which can also fit that bill for quick fixes, but I want deep down support for simple interception.  Conversations with &lt;a href="http://bradwilson.typepad.com/"&gt;Brad Wilson&lt;/a&gt; led me to ObjectBuilder2 and some spikes that they had with a customer DependencyContainer.  So parts of me wondered why that wasn't leveraged at all.  Let's take a look at what was implemented in the base of ObjectBuilder2.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Interception in ObjectBuilder2&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
ObjectBuilder2 was a project by Brad Wilson and &lt;a href="http://blogs.msdn.com/scottdensmore/"&gt;Scott Densmore&lt;/a&gt; which took the original ObjectBuilder, which was really meant for CAB and not a real container, and made some changes and improvements.  Such improvements also came with a few samples of things you can do with it such as a DependencyContainer sample.  In here, there are a few interesting pieces.  Most of which lie in the interception pieces.  Let's take a look at each type below of the ones supported.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red255\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2         \cf3 public\cf1  \cf3 void\cf1  InterceptInterface&amp;lt;T&amp;gt;(\cf4 MethodInfo\cf1  interfaceMethod,\par ??                                          \cf3 params\cf1  \cf5 IInterceptionHandler\cf1 [] handlers)\par ??        \{\par ??            Intercept&amp;lt;\cf4 InterfaceInterceptionPolicy\cf1 , \cf5 IInterfaceInterceptionPolicy\cf1 &amp;gt;(\cf3 typeof\cf1 (T), interfaceMethod, handlers);\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  InterceptInterface(\cf4 Type\cf1  typeToIntercept,\par ??                                       \cf4 MethodInfo\cf1  interfaceMethod,\par ??                                       \cf3 params\cf1  \cf5 IInterceptionHandler\cf1 [] handlers)\par ??        \{\par ??            Intercept&amp;lt;\cf4 InterfaceInterceptionPolicy\cf1 , \cf5 IInterfaceInterceptionPolicy\cf1 &amp;gt;(typeToIntercept, interfaceMethod, handlers);\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  InterceptRemoting&amp;lt;T&amp;gt;(\cf4 MethodInfo\cf1  method,\par ??                                         \cf3 params\cf1  \cf5 IInterceptionHandler\cf1 [] handlers)\par ??        \{\par ??            Intercept&amp;lt;\cf4 RemotingInterceptionPolicy\cf1 , \cf5 IRemotingInterceptionPolicy\cf1 &amp;gt;(\cf3 typeof\cf1 (T), method, handlers);\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  InterceptRemoting(\cf4 Type\cf1  typeToIntercept,\par ??                                      \cf4 MethodInfo\cf1  method,\par ??                                      \cf3 params\cf1  \cf5 IInterceptionHandler\cf1 [] handlers)\par ??        \{\par ??            Intercept&amp;lt;\cf4 RemotingInterceptionPolicy\cf1 , \cf5 IRemotingInterceptionPolicy\cf1 &amp;gt;(typeToIntercept, method, handlers);\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  InterceptVirtual&amp;lt;T&amp;gt;(\cf4 MethodInfo\cf1  method,\par ??                                        \cf3 params\cf1  \cf5 IInterceptionHandler\cf1 [] handlers)\par ??        \{\par ??            Intercept&amp;lt;\cf4 VirtualInterceptionPolicy\cf1 , \cf5 IVirtualInterceptionPolicy\cf1 &amp;gt;(\cf3 typeof\cf1 (T), method, handlers);\par ??        \}\par ??\par ??        \cf3 public\cf1  \cf3 void\cf1  InterceptVirtual(\cf4 Type\cf1  typeToIntercept,\par ??                                     \cf4 MethodInfo\cf1  method,\par ??                                     \cf3 params\cf1  \cf5 IInterceptionHandler\cf1 [] handlers)\par ??        \{\par ??            Intercept&amp;lt;\cf4 VirtualInterceptionPolicy\cf1 , \cf5 IVirtualInterceptionPolicy\cf1 &amp;gt;(typeToIntercept, method, handlers);\par ??        \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptInterface&amp;lt;T&amp;gt;(&lt;span style="color: yellow;"&gt;MethodInfo&lt;/span&gt; interfaceMethod,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                          &lt;span style="color: rgb(255, 128, 0);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;[] handlers)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptInterface(&lt;span style="color: yellow;"&gt;Type&lt;/span&gt; typeToIntercept,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                       &lt;span style="color: yellow;"&gt;MethodInfo&lt;/span&gt; interfaceMethod,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                       &lt;span style="color: rgb(255, 128, 0);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;[] handlers)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptRemoting&amp;lt;T&amp;gt;(&lt;span style="color: yellow;"&gt;MethodInfo&lt;/span&gt; method,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                         &lt;span style="color: rgb(255, 128, 0);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;[] handlers)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptRemoting(&lt;span style="color: yellow;"&gt;Type&lt;/span&gt; typeToIntercept,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                      &lt;span style="color: yellow;"&gt;MethodInfo&lt;/span&gt; method,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                      &lt;span style="color: rgb(255, 128, 0);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;[] handlers)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptVirtual&amp;lt;T&amp;gt;(&lt;span style="color: yellow;"&gt;MethodInfo&lt;/span&gt; method,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                        &lt;span style="color: rgb(255, 128, 0);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;[] handlers)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptVirtual(&lt;span style="color: yellow;"&gt;Type&lt;/span&gt; typeToIntercept,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                     &lt;span style="color: yellow;"&gt;MethodInfo&lt;/span&gt; method,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                     &lt;span style="color: rgb(255, 128, 0);"&gt;params&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;[] handlers)&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Now with this, you can see there are three different ways of intercepting, through interfaces, virtual methods or through remoting.  We also have the ability to intercept through attributes or through code.  Let's walk through a test to see how intercepting through attributes might work.  &lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green255\blue0;\red255\green128\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2             [\cf3 Fact\cf1 ]\par ??            \cf4 public\cf1  \cf4 void\cf1  InterceptViaAttributes()\par ??            \{\par ??                \cf3 Recorder\cf1 .Records.Clear();\par ??                \cf3 DependencyContainer\cf1  container = \cf4 new\cf1  \cf3 DependencyContainer\cf1 ();\par ??                container.RegisterTypeMapping&amp;lt;\cf5 ISpy\cf1 , \cf3 SpyInterfaceAttributes\cf1 &amp;gt;();\par ??\par ??                \cf5 ISpy\cf1  obj = container.Get&amp;lt;\cf5 ISpy\cf1 &amp;gt;();\par ??                obj.InterceptedMethod();\par ??\par ??                \cf3 Assert\cf1 .Equal(3, \cf3 Recorder\cf1 .Records.Count);\par ??                \cf3 Assert\cf1 .Equal(\cf6 "Before Method"\cf1 , \cf3 Recorder\cf1 .Records[0]);\par ??                \cf3 Assert\cf1 .Equal(\cf6 "In Method"\cf1 , \cf3 Recorder\cf1 .Records[1]);\par ??                \cf3 Assert\cf1 .Equal(\cf6 "After Method"\cf1 , \cf3 Recorder\cf1 .Records[2]);\par ??            \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;            [&lt;span style="color: yellow;"&gt;Fact&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptViaAttributes()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Clear();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;DependencyContainer&lt;/span&gt; container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;DependencyContainer&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                container.RegisterTypeMapping&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ISpy&lt;/span&gt;, &lt;span style="color: yellow;"&gt;SpyInterfaceAttributes&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(43, 145, 175);"&gt;ISpy&lt;/span&gt; obj = container.Get&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ISpy&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                obj.InterceptedMethod();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(3, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Count);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: lime;"&gt;"Before Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[0]);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: lime;"&gt;"In Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[1]);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Assert&lt;/span&gt;.Equal(&lt;span style="color: lime;"&gt;"After Method"&lt;/span&gt;, &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records[2]);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Of course there wouldn't be tests in here without using &lt;a href="http://www.codeplex.com/xunit"&gt;xUnit.NET&lt;/a&gt; of course.  Hope to cover that soon enough.  Anyhow, as you can see, it's pretty simple to register types in here and then check the expectations through the recorder to see whether the actions happened.  To find out what the ISpy and SpyInterfaceAttribtues are actually doing, let's dig through the code.  &lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red43\green145\blue175;\red255\green255\blue0;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2             \cf3 public\cf1  \cf3 interface\cf1  \cf4 ISpy\par ??\cf1             \{\par ??                \cf3 void\cf1  InterceptedMethod();\par ??                \cf3 void\cf1  ThrowsException();\par ??            \}\par ??\par ??            \cf3 internal\cf1  \cf3 sealed\cf1  \cf3 class\cf1  \cf5 SpyInterface\cf1  : \cf4 ISpy\par ??\cf1             \{\par ??                \cf3 public\cf1  \cf3 void\cf1  InterceptedMethod()\par ??                \{\par ??                    \cf5 Recorder\cf1 .Records.Add(\cf6 "In Method"\cf1 );\par ??                \}\par ??\par ??                \cf3 public\cf1  \cf3 void\cf1  ThrowsException()\par ??                \{\par ??                    \cf5 Recorder\cf1 .Records.Add(\cf6 "In Method"\cf1 );\par ??                    \cf3 throw\cf1  \cf3 new\cf1  \cf5 Exception\cf1 ();\par ??                \}\par ??            \}\par ??\par ??            \cf3 internal\cf1  \cf3 sealed\cf1  \cf3 class\cf1  \cf5 SpyInterfaceAttributes\cf1  : \cf4 ISpy\par ??\cf1             \{\par ??                [\cf5 InterfaceIntercept\cf1 (\cf3 typeof\cf1 (\cf5 RecordingHandler\cf1 ))]\par ??                \cf3 public\cf1  \cf3 void\cf1  InterceptedMethod()\par ??                \{\par ??                    \cf5 Recorder\cf1 .Records.Add(\cf6 "In Method"\cf1 );\par ??                \}\par ??\par ??                \cf3 public\cf1  \cf3 void\cf1  ThrowsException()\par ??                \{\par ??                    \cf3 throw\cf1  \cf3 new\cf1  \cf5 Exception\cf1 ();\par ??                \}\par ??            \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ISpy&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptedMethod();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; ThrowsException();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;sealed&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;SpyInterfaceAttributes&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;ISpy&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                [&lt;span style="color: yellow;"&gt;InterfaceIntercept&lt;/span&gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: yellow;"&gt;RecordingHandler&lt;/span&gt;))]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; InterceptedMethod()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                    &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: lime;"&gt;"In Method"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; ThrowsException()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                    &lt;span style="color: rgb(255, 128, 0);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;Exception&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
What this class allows us to do is to register an intercepting interface handler, in this case the RecordingHandler.  What we intend to have done is that we record a message once we're in the method.  Then our interceptor can put in calls before and after our method call just to prove a point.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  ObjectBuilder\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 RecordingHandler\cf3  : \cf5 IInterceptionHandler\par ??\cf3     \{\par ??        \cf1 readonly\cf3  \cf1 string\cf3  message;\par ??\par ??        \cf1 public\cf3  RecordingHandler()\par ??        \{\par ??            message = \cf6 ""\cf3 ;\par ??        \}\par ??\par ??        \cf1 public\cf3  RecordingHandler(\cf1 string\cf3  message)\par ??        \{\par ??            \cf1 this\cf3 .message = \cf1 string\cf3 .Format(\cf6 " (\{0\})"\cf3 , message);\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf5 IMethodReturn\cf3  Invoke(\cf5 IMethodInvocation\cf3  call,\par ??                                    \cf5 GetNextHandlerDelegate\cf3  getNext)\par ??        \{\par ??            \cf4 Recorder\cf3 .Records.Add(\cf6 "Before Method"\cf3  + message);\par ??            \cf5 IMethodReturn\cf3  result = getNext().Invoke(call, getNext);\par ??            \cf4 Recorder\cf3 .Records.Add(\cf6 "After Method"\cf3  + message);\par ??            \cf1 return\cf3  result;\par ??        \}\par ??    \}\par ??\}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; ObjectBuilder&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;RecordingHandler&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptionHandler&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; message;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; RecordingHandler()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            message = &lt;span style="color: lime;"&gt;""&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; RecordingHandler(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; message)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;this&lt;/span&gt;.message = &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: lime;"&gt;" ({0})"&lt;/span&gt;, message);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IMethodReturn&lt;/span&gt; Invoke(&lt;span style="color: rgb(43, 145, 175);"&gt;IMethodInvocation&lt;/span&gt; call,&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                    &lt;span style="color: rgb(43, 145, 175);"&gt;GetNextHandlerDelegate&lt;/span&gt; getNext)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: lime;"&gt;"Before Method"&lt;/span&gt; + message);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;IMethodReturn&lt;/span&gt; result = getNext().Invoke(call, getNext);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;Recorder&lt;/span&gt;.Records.Add(&lt;span style="color: lime;"&gt;"After Method"&lt;/span&gt; + message);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; result;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
This IInterceptionHandler interface handles the basic interception tasks of doing some before and after work on the given method.  Here it is doing nothing special but recording a message before and after intercepting the method call.  I encourage you to dig through this a bit more and understand where it is coming from, because it's good stuff and heck, you might learn some IL emitting as well.  It's a shame I didn't see some of this IP get rolled into Unity, but we can hope some of it does.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Interception in Castle Windsor&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Like above with ObjectBuilder2, Castle Windsor has a lightweight interception capability as well.  I covered this in a previous post, but I'll elaborate on it further.  There isn't much on Windsor interception documentation, but you can read about that &lt;a href="http://www.castleproject.org/container/documentation/v1rc3/usersguide/interceptors.html"&gt;here&lt;/a&gt;.  To take advantage of method interception, simply implement the IInterceptor interface which is marked below.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2     \cf3 public\cf1  \cf3 interface\cf1  \cf4 IInterceptor\par ??\cf1     \{\par ??        \cf3 void\cf1  Intercept(\cf4 IInvocation\cf1  invocation);\par ??    \}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptor&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Intercept(&lt;span style="color: rgb(43, 145, 175);"&gt;IInvocation&lt;/span&gt; invocation);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And then we can implement a simple logger interceptor which goes ahead and logs the before and after information as well as anything else you might want to log that comes from the method signature such as arguments, method name, targets, etc.  Here, I'm doing nothing special at all, but play around with the IInvocation interface to find out what you can do.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  Castle.Core.Interceptor;\par ??\par ??\cf1 namespace\cf3  CastleSamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 LoggingInterceptor\cf3  : \cf5 IInterceptor\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf4 DebugLogger\cf3  logger = \cf1 new\cf3  \cf4 DebugLogger\cf3 ();\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  Intercept(\cf5 IInvocation\cf3  invocation)\par ??        \{\par ??            logger.Log(\cf6 "Before Method"\cf3 );\par ??            invocation.Proceed();\par ??            logger.Log(\cf6 "After Method"\cf3 );\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Castle.Core.Interceptor;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; CastleSamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;LoggingInterceptor&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IInterceptor&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: yellow;"&gt;DebugLogger&lt;/span&gt; logger = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;DebugLogger&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Intercept(&lt;span style="color: rgb(43, 145, 175);"&gt;IInvocation&lt;/span&gt; invocation)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger.Log(&lt;span style="color: lime;"&gt;"Before Method"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            invocation.Proceed();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger.Log(&lt;span style="color: lime;"&gt;"After Method"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Like I said above, I am doing nothing special here other than to show that I can log before and after calls, and I have the option of doing more whether I want to proceed with the method call or not.  I can easily register the interceptor either through code, through Binsor or through the XML muck.  An post of mine goes through that &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/23/118842.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
To me, these lightweight interceptors are nice, but I don't get much value out of them just yet outside of logging and such.  Ayende has similar thoughts about the uses of AOP in Windsor &lt;a href="http://www.ayende.com/Blog/archive/2007/03/13/Recommended-approaches-to-AOP-with-Windsor.aspx"&gt;here&lt;/a&gt;.  He also covers doing a Policy Injection Application Block style approach in Windsor as well &lt;a href="http://www.ayende.com/Blog/archive/2007/03/07/Building-the-Policy-Injection-in-40-Minutes-with-Windsor.aspx"&gt;here&lt;/a&gt;.  &lt;br /&gt;
&lt;br /&gt;
One off the topics discussed at DC ALT.NET was about using Windsor Interception to implement the Unit of Work pattern to implement undo logic for a WPF application.  It was a pretty interesting approach to the issue and I'll definitely have to dig into that a little deeper as well.  I'm hoping &lt;a href="http://blogs.ent0.com/blogs/philmcmillan/"&gt;Phil McMillan&lt;/a&gt; starts blogging more anyways...  But, obviously there are uses of interception and AOP in the enterprise and I'll get to that in the next post in the series.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, interception is an interesting topic that needs to be explored a bit more before I'd call this subject done.   After all, I haven't touch most other containers, and I definitely want to get into AOP and Spring.NET as it is a topic I'd like to dive a little deeper into as well as AOP in the Enterprise model.  Things that make the .NET rramework bend in all sorts of ways is always a worth cause.  Anyhow, I hope this dive again into the subject is useful and any feedback is appreciated.  Until next time...
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/26/120764.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/26/120764.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120764"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120764" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120764.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/26/120764.aspx</guid>
            <pubDate>Wed, 26 Mar 2008 06:33:03 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120764.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/26/120764.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120764.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120764.aspx</trackback:ping>
        </item>
        <item>
            <title>RockNUG Meeting 3/12/2008 - Refactoring in C#</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/10/120438.aspx</link>
            <description>The &lt;a href="http://rocknug.org/"&gt;Rockville .NET User Group (RockNUG)&lt;/a&gt; will be holding their next meeting on Wednesday, March 12th, 2008 from 6:30PM-9:00PM.  This month, they'll be having a pretty interesting topic on refactoring in C# with &lt;a href="http://weblogs.asp.net/jcogley/"&gt;Jonathan Cogley&lt;/a&gt;.  I've had my refactoring and agile boots on lately, so I can definitely relate.  I don't know what I would do though without my &lt;a href="http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.0+Nightly+Builds"&gt;Resharper 4.0 Nightly Builds&lt;/a&gt;...  I've had a few issues here and there, but nothing to discourage me from continuing usage.&lt;br /&gt;
&lt;br /&gt;
Anyhow, here are the details:&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Location:&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://rocknug.org/Default.aspx?tabid=116"&gt;Montgomery College, Rockville&lt;br /&gt;
Humanities Building - Room 103&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold; font-style: italic;"&gt;Refactoring in C# - Bad code to better code&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;presented by &lt;a href="http://weblogs.asp.net/jcogley/"&gt;Jonathan Cogley&lt;/a&gt;&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;What could be more fun on a Wednesday evening than critiquing some bad&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;code and making it better? :) Come along to learn how to clean code like&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;the &lt;a href="http://www.thycotic.com/"&gt;Thycotic&lt;/a&gt; team. What do we look for? How do we take small steps to&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;keep it working? What tips and tricks make it easier? This session&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;will be code, code and more code (and a few unit tests of course!).&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;Jonathan Cogley is the founder and CEO of &lt;a href="http://www.thycotic.com/"&gt;thycotic&lt;/a&gt; - a software&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;development company operating in the Washington DC Metro Area with&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;offices in Vienna, Virginia. Jonathan has worked for many interesting&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;companies over the last decade as a software consultant in both the UK&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;and the USA. His company has released various .NET projects and APIs&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;including an implementation of Remote Scripting for .NET, a database&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;platform independent data access layer for ISVs and various tools for&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;the Test Driven Developer. Test Driven Development (TDD) is the&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;cornerstone of the thycotic approach to software development and the&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;company is committed to innovate TDD on the Microsoft .NET platform with&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;new techniques and tools. Jonathan is also a columnist and editor for&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;the popular ASP.NET Web site, ASPAlliance. He is an active member in the&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;developer community and speaks regularly at various .NET User Groups,&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;conferences and code camps across the US. Jonathan is recognized by&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;Microsoft as an MVP for C# and has also been invited to join the select&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;group of the ASPInsiders who have interactions with the product teams at&lt;/span&gt;&lt;br style="font-style: italic;" /&gt;
&lt;span style="font-style: italic;"&gt;Microsoft.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The schedule for the event is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;table cellspacing="1" cellpadding="1" border="0" align="" summary="" style="width: 567px; height: 1px;"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;n00b Session&lt;/td&gt;
            &lt;td&gt;6:30 - 7:00&lt;/td&gt;
            &lt;td&gt;ASP.NET GridView Part III&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;Pizza/Announcements&lt;/td&gt;
            &lt;td&gt;7:00 - 7:30&lt;/td&gt;
            &lt;td&gt; &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;Featured Presentation&lt;/td&gt;
            &lt;td&gt;7:30 - 9:00&lt;/td&gt;
            &lt;td&gt;Jonathan Cogley: Refactoring in C# - Bad code to better code&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
Hope to see a great crowd there!  I'm looking forward to it.
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/10/120438.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/10/120438.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120438"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120438" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120438.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/10/120438.aspx</guid>
            <pubDate>Mon, 10 Mar 2008 23:39:24 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120438.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/10/120438.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120438.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120438.aspx</trackback:ping>
        </item>
        <item>
            <title>IoC Container, Unity and Breaking Changes Galore</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/07/120336.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Update: &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/25/ioc-and-unity-the-basics-and-interception.aspx"&gt;IoC and Unity - The Basics and Interception&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As &lt;a href="http://blogs.msdn.com/agile/"&gt;Grigori Melnik&lt;/a&gt; noted on my blog previously as well as his &lt;a href="http://blogs.msdn.com/agile/archive/2008/03/04/unity-project-heartbeat.aspx"&gt;own&lt;/a&gt;, there was a brand new drop of the &lt;a href="http://www.codeplex.com/unity"&gt;Unity Application Block&lt;/a&gt; as of &lt;a href="http://www.codeplex.com/unity/Release/ProjectReleases.aspx?ReleaseId=11319"&gt;March 4th&lt;/a&gt;.  This by far was a huge update with a lot of breaking changes.  That teaches me to use a CTP of any product and blog about it actively as it compares to other &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control"&gt;Inversion of Control (IoC)&lt;/a&gt; containers.  Glad I didn't do a lot on ASP.NET MVC just yet but I have a few good projects going on the side with that now.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Where I've Been Before&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As noted here before, I've been spending some time actively comparing the Unity Application Block to other IoC containers and what each offers.  Let's get caught up to my previous posts:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/18/119744.aspx"&gt;IoC and the Unity Application Block&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/22/119911.aspx"&gt;IoC and the Unity Application Block - Going Deeper&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx"&gt;IoC and the Unity Application Block Once Again&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/03/04/120185.aspx"&gt;IoC Containers, Unity and ObjectBuilder2 - The Saga Continues&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
I'm probably going to change the code on each one just so that you all don't get angry about code from me not working, so stay tuned, it will get done.  But, keep in mind, it is still CTP, and I'd rather concentrate on the concepts as well.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;What's Changed&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you may notice if you did any of the code snippets I published, they sure as heck don't build anymore.  So, let's enumerate the changes made so far:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;UnityContainer method Register&amp;lt;TFrom, TTo&amp;gt;() becomes RegisterType&amp;lt;TFrom, TTo&amp;gt;()&lt;/li&gt;
    &lt;li&gt;UnityContainer method Get&amp;lt;T&amp;gt;() becomes Resolve&amp;lt;T&amp;gt;&lt;/li&gt;
    &lt;li&gt;UnityContainer method SetSingleton&amp;lt;T&amp;gt; removed&lt;/li&gt;
    &lt;li&gt;UnityContainer method RegisterType&amp;lt;TFrom, TTo&amp;gt; accepts a LifetimeManager to create Singletons&lt;/li&gt;
    &lt;li&gt;Added ContainerControlledLifetimeManager and ExternallyControlledLifetimeManager&lt;/li&gt;
    &lt;li&gt;Removed DependencyAttribute NotPresentBehavior property and enum&lt;/li&gt;
    &lt;li&gt;Added UnityContainer CreateChildContainer method to create child sandboxes&lt;/li&gt;
    &lt;li&gt;Reversed the parameters for UnityContainer method RegisterInstance&amp;lt;T&amp;gt;(value, key) to RegisterInstance&amp;lt;T&amp;gt;(key, value)&lt;/li&gt;
&lt;/ul&gt;
As you can see, some of these changes can be seen as quite annoying especially if I were to have a method such as the following and I can't find the error until I sit and read the code through and through:&lt;br /&gt;
&lt;br /&gt;
Old:&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red43\green145\blue175;\red255\green128\blue0;\red255\green255\blue0;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2             \cf3 IUnityContainer\cf1  container = \cf4 new\cf1  \cf5 UnityContainer\cf1 ();\par ??            container\par ??                .RegisterType&amp;lt;\cf3 ILogger\cf1 , \cf5 ConsoleLogger\cf1 &amp;gt;(\cf4 new\cf1  \cf5 ContainerControlledLifetimeManager\cf1 ())\par ??                .RegisterInstance&amp;lt;\cf4 string\cf1 &amp;gt;(\cf6 "defaultFromAddress"\cf1 , \cf6 "administrator@example.com"\cf1 );}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;container&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    .RegisterType&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;, &lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;ContainerControlledLifetimeManager&lt;/span&gt;())&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    .RegisterInstance&amp;lt;&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color: lime;"&gt;"administrator@example.com"&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;/span&gt;&lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;/span&gt;&lt;span style="color: lime;"&gt;&lt;/span&gt;);&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And sure enough, it blew up due to the fact that it seemed just fine because it was RegisterInstance&amp;lt;string&amp;gt;(string, string) and instead I had to change it to this to get it to work.&lt;br /&gt;
&lt;br /&gt;
New:&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red43\green145\blue175;\red255\green128\blue0;\red255\green255\blue0;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2             \cf3 IUnityContainer\cf1  container = \cf4 new\cf1  \cf5 UnityContainer\cf1 ();\par ??            container\par ??                .RegisterType&amp;lt;\cf3 ILogger\cf1 , \cf5 ConsoleLogger\cf1 &amp;gt;(\cf4 new\cf1  \cf5 ContainerControlledLifetimeManager\cf1 ())\par ??                .RegisterInstance&amp;lt;\cf4 string\cf1 &amp;gt;(\cf6 "defaultFromAddress"\cf1 , \cf6 "administrator@example.com"\cf1 );}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;container&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    .RegisterType&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;, &lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;ContainerControlledLifetimeManager&lt;/span&gt;())&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    .RegisterInstance&amp;lt;&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;/span&gt;&lt;span style="color: lime;"&gt;"administrator@example.com"&lt;span style="color: rgb(255, 255, 255);"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: lime;"&gt;&lt;/span&gt;&lt;span style="color: lime;"&gt;&lt;/span&gt;);&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Nothing from what I can tell changed in the XML configuration, but I prefer to register my types by code instead.  The only thing I really like to switch out from time to time is a Logger of some sort.&lt;br /&gt;
&lt;br /&gt;
Another interesting aspect is the concept of child containers in their own sandbox as it were.  Take for example, we have two loggers, a DebugLogger and a ConsoleLogger.  We have the ability to have these registered in two different child containers all managed by the parent.  Let's walk through a simple example of this.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  Microsoft.Practices.Unity;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 class\cf3  \cf4 Program\par ??\cf3     \{\par ??        \cf1 static\cf3  \cf1 void\cf3  Main(\cf1 string\cf3 [] args)\par ??        \{\par ??            \cf4 UnityContainer\cf3  parentContainer = \cf1 new\cf3  \cf4 UnityContainer\cf3 ();\par ??            \cf5 IUnityContainer\cf3  childContainer1 = parentContainer.CreateChildContainer();\par ??            childContainer1.RegisterType&amp;lt;\cf5 ILogger\cf3 , \cf4 ConsoleLogger\cf3 &amp;gt;(\cf1 new\cf3  \cf4 ContainerControlledLifetimeManager\cf3 ());\par ??            \cf5 IUnityContainer\cf3  childContainer2 = parentContainer.CreateChildContainer();\par ??            childContainer2.RegisterType&amp;lt;\cf5 ILogger\cf3 , \cf4 DebugLogger\cf3 &amp;gt;(\cf1 new\cf3  \cf4 ContainerControlledLifetimeManager\cf3 ());\par ??\par ??            \cf5 ILogger\cf3  logger1 = childContainer1.Resolve&amp;lt;\cf5 ILogger\cf3 &amp;gt;();\par ??            \cf5 ILogger\cf3  logger2 = childContainer2.Resolve&amp;lt;\cf5 ILogger\cf3 &amp;gt;();\par ??            logger1.Log(\cf6 "Foo"\cf3 );\par ??            logger2.Log(\cf6 "Bar"\cf3 );\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Program&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt; parentContainer = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; childContainer1 = parentContainer.CreateChildContainer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            childContainer1.RegisterType&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;, &lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;ContainerControlledLifetimeManager&lt;/span&gt;());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; childContainer2 = parentContainer.CreateChildContainer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            childContainer2.RegisterType&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;, &lt;span style="color: yellow;"&gt;DebugLogger&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;ContainerControlledLifetimeManager&lt;/span&gt;());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; logger1 = childContainer1.Resolve&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; logger2 = childContainer2.Resolve&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger1.Log(&lt;span style="color: lime;"&gt;"Foo"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger2.Log(&lt;span style="color: lime;"&gt;"Bar"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
What seemed a little annoying to me is that CreateChildContainer is not available from the IUnityContainer, and instead only from the UnityContainer concrete class instead.  But as you can see, I create two loggers each in their own sandbox, one a DebugLogger and one the ConsoleLogger.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;What I'd Like To See&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As I've said before, I'm not entirely sold on the Unity Application Block as I like a lot of the other ones in the Open Source Community as well including &lt;a href="http://www.castleproject.org/"&gt;Castle Windsor&lt;/a&gt;, &lt;a href="http://structuremap.sourceforge.net/"&gt;StructureMap&lt;/a&gt; and &lt;a href="http://www.springframework.net/"&gt;Spring.NET&lt;/a&gt;.  It's heartening that they are taking a lot of advice from the community to heart and having quick drops for public approval.  When people are evaluating IoC containers, it's critical that you have a list of essential features that the container must support.  You may also note that your needs for this may change from project to project, so don't assume that if it worked well here that it will suit your needs on all projects.  Due diligence must be done in tool and framework analysis to get the right tool for the right job.&lt;br /&gt;
&lt;br /&gt;
With that in mind, I have a few things that I'm looking for right now in an IoC container.  Some of these requirements are as follows:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Must be lightweight (No heavy XML lifting required)&lt;/li&gt;
    &lt;li&gt;Must support interception and AOP with runtime weaving (compile time might be nice)&lt;/li&gt;
    &lt;li&gt;Should be opinionated so that I don't need to mark my dependencies in my constructor, instead match by name&lt;/li&gt;
    &lt;li&gt;When I ask for a logger, give me one and I don't care which&lt;/li&gt;
    &lt;li&gt;Support easy object registration through fluent interfaces&lt;/li&gt;
&lt;/ul&gt;
But like I said, it evolves quickly and changes from project to project.  What's your list and why?&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Further Thoughts About IoC&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://blogs.msdn.com/nickmalik/"&gt;Nick Malik&lt;/a&gt; recently blogged about IoC container and their overuse in a two part blog series &lt;a href="http://blogs.msdn.com/nickmalik/archive/2008/02/15/what-is-the-tradeoff-with-inversion-of-control-ioc.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/nickmalik/archive/2008/02/20/inversion-of-control-part-two.aspx"&gt;here&lt;/a&gt;.  In his first post, he tends to think that people are religious about the use of IoC containers and not just the &lt;a href="http://en.wikipedia.org/wiki/Dependency_Injection"&gt;Dependency Injection&lt;/a&gt; pattern in particular.  In the second post, he covers that the use of the IoC container is only as good as the team that understands its impact and applicability.  Most tools have their limits and uses.  Mocking containers have the same issue.  Once you start mocking for parts of your tests, then there is a good chance for abuse and overuse as well.  I see his point, but I disagree that many teams are not up for IoC containers and general good design practices of Dependency Injection.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Wrapping It Up&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Next time, I'd like to get into the extensibility model of each container in terms registering extensions and so on.  In the mean time, I hope you go and evaluate your needs for an IoC container, even whether you need one or not.  Until next time... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/07/120336.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/07/120336.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120336"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120336" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120336.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/07/120336.aspx</guid>
            <pubDate>Fri, 07 Mar 2008 08:13:25 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120336.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/07/120336.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120336.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120336.aspx</trackback:ping>
        </item>
        <item>
            <title>IoC and the Unity Application Block Once Again</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx</link>
            <description>&lt;span style="font-weight: bold;"&gt;Update:  Fixed code changed from CTP and More in the series:&lt;/span&gt;&lt;br style="font-weight: bold;" /&gt;
&lt;ul style="font-weight: bold;"&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/03/04/120185.aspx"&gt;IoC Containers, Unity and ObjectBuilder2 - The Saga Continues&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/03/07/120336.aspx"&gt;IoC Container, Unity and Breaking Changes Galore&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
After the reaction of my &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/22/119911.aspx"&gt;last post&lt;/a&gt; of talking about IoC and the &lt;a href="http://www.codeplex.com/unity"&gt;Unity Application Block&lt;/a&gt;, I thought I'd include a few more samples of using Unity and how they compare with other IoC containers.  I realized after my first one, that I didn't give any love to StructureMap and I'm going to fix that for a brief sample as well.  I realize there are plenty of IoC containers out there including Spring, but quite frankly I've found it heavier than most, so I'm going to stick with Unity, &lt;a href="http://castleproject.org"&gt;Castle Windsor&lt;/a&gt; and &lt;a href="http://structuremap.sourceforge.net/"&gt;StructureMap &lt;/a&gt;for this example.&lt;br /&gt;
&lt;br /&gt;
Before I continue, check out &lt;a href="http://www.davidhayden.com/"&gt;David Hayden's&lt;/a&gt; screencast of &lt;a href="http://www.pnpguidance.net/Screencast/UnityDependencyInjectionIoCScreencast.aspx"&gt;IoC with ASP.NET MVC&lt;/a&gt; for some more interesting ideas regarding IoC and Unity.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Setter Injection versus Constructor Injection&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I've been down the road of constructor injection versus setter injection.  My opinion is that you try to inject the most you can through your constructor such as in a Model View Presenter, injecting the View and the Service Layer.  Now, you may have cross-cutting concerns such as logging that you may want to swap out, but putting it in the constructor can just get ugly and you can set a default logger in your class anyways such as a NullLogger.  Martin Fowler, as always, covers this topic &lt;a href="http://www.martinfowler.com/articles/injection.html#ConstructorVersusSetterInjection"&gt;here &lt;/a&gt;and it's quite interesting as it is an open debate.&lt;br /&gt;
&lt;br /&gt;
The other option I've done down this road was to create an IContext interface which is injected through the constructor that has some of the cross-cutting concerns wrapped up into it, but for now, let's just walk through a sample of having setter injection as well.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Get Down to Details&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now that we got all the other stuff out of the way, let's go ahead and set up some basic examples in Unity, Castle Windsor and StructureMap doing setter injection.  I'll basically take the code from last time and apply it here as well.  So, let's start out with the Unity Application Block Sample:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 interface\cf3  \cf4 ILogger\par ??\cf3     \{\par ??        \cf1 void\cf3  Log(\cf1 string\cf3  message);\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Log(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; message);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And we have two implementations, the NullLogger (the default) and the ConsoleLogger (the override).  Let's go through each of those.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 NullLogger\cf3  : \cf5 ILogger\par ??\cf3     \{\par ??        \cf1 public\cf3  \cf1 void\cf3  Log(\cf1 string\cf3  message)\par ??        \{\par ??            \cf6 // Do nothing\par ??\cf3         \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;NullLogger&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Log(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; message)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: lime;"&gt;// Do nothing&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  System;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 ConsoleLogger\cf3  : \cf5 ILogger\par ??\cf3     \{\par ??        \cf1 public\cf3  ConsoleLogger()\par ??        \{\par ??            \cf4 Console\cf3 .WriteLine(\cf6 "Hello from constructor"\cf3 );\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  Log(\cf1 string\cf3  message)\par ??        \{\par ??            \cf4 Console\cf3 .WriteLine(message);\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; System;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Log(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; message)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;Console&lt;/span&gt;.WriteLine(message);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Now that I have these two implementations, I won't bother repeating these for the others unless they specifically change, which they shouldn't.  Now, to my implementation details of my CustomerTasks object.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  Microsoft.Practices.Unity;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 CustomerTasks\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf5 ILogger\cf3  logger = \cf1 new\cf3  \cf4 NullLogger\cf3 ();\par ??\par ??        [\cf4 Dependency\cf3 ]\par ??        \cf1 public\cf3  \cf5 ILogger\cf3  Logger\par ??        \{\par ??            \cf1 get\cf3  \{ \cf1 return\cf3  logger; \}\par ??            \cf1 set\cf3  \{ logger = \cf1 value\cf3 ; \}\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SaveCustomer()\par ??        \{\par ??            Logger.Log(\cf6 "Saved customer"\cf3 );\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; logger = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;NullLogger&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        [&lt;span style="color: yellow;"&gt;Dependency&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; Logger&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; logger; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;set&lt;/span&gt; { logger = &lt;span style="color: rgb(255, 128, 0);"&gt;value&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; SaveCustomer()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            Logger.Log(&lt;span style="color: lime;"&gt;"Saved customer"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
As you may note, I set the default implementation of my logger to a NullLogger because by default, I don't care about logging, so it's about the same as a NoOp.  But, if I want to change that, I can through my setter injection.  This goes for any cross-cutting concern.  I also marked my Logger property with the DependencyAttribute which basically says that give me the ILogger instance registered when you go through the container to create it.  This of course requires class modification, so it's not a simple rip and replace as it was with constructor injection.  So, now let's look at the implementation of our configuration, much as before.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  System.Configuration;\par ??\cf1 using\cf3  Microsoft.Practices.Unity;\par ??\cf1 using\cf3  Microsoft.Practices.Unity.Configuration;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 class\cf3  \cf4 Program\par ??\cf3     \{\par ??        \cf1 static\cf3  \cf1 void\cf3  Main(\cf1 string\cf3 [] args)\par ??        \{\par ??            \cf5 IUnityContainer\cf3  container = \cf1 new\cf3  \cf4 UnityContainer\cf3 ();\par ??            \cf4 UnityConfigurationSection\cf3  section = (\cf4 UnityConfigurationSection\cf3 )\cf4 ConfigurationManager\cf3 .GetSection(\cf6 "unity"\cf3 );\par ??            section.Containers.Default.GetConfigCommand().Configure(container);\par ??            \cf4 CustomerTasks\cf3  tasks1 = container.Get&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            \cf4 CustomerTasks\cf3  tasks2 = container.Get&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            tasks1.SaveCustomer();\par ??            tasks2.SaveCustomer();   \par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; System.Configuration;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity.Configuration;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Program&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;UnityConfigurationSection&lt;/span&gt; section = (&lt;span style="color: yellow;"&gt;UnityConfigurationSection&lt;/span&gt;)&lt;span style="color: yellow;"&gt;ConfigurationManager&lt;/span&gt;.GetSection(&lt;span style="color: lime;"&gt;"unity"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            section.Containers.Default.GetConfigCommand().Configure(container);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks1 = container.Get&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks2 = container.Get&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks1.SaveCustomer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks2.SaveCustomer();   &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And the configuration file will look much like before as:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 &amp;lt;?xml \cf3 version\cf1 ="\cf4 1.0\cf1 " \cf3 encoding\cf1 ="\cf4 utf-8\cf1 " ?&amp;gt;\par ??&amp;lt;configuration&amp;gt;\par ??  &amp;lt;configSections&amp;gt;\par ??    &amp;lt;section \cf3 name\cf1 ="\cf4 unity\cf1 "\par ??             \cf3 type\cf1 ="\cf4 Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,\par ??                   Microsoft.Practices.Unity.Configuration\cf1 " /&amp;gt;\par ??  &amp;lt;/configSections&amp;gt;\par ??  &amp;lt;unity&amp;gt;\par ??    &amp;lt;containers&amp;gt;\par ??      &amp;lt;container&amp;gt;\par ??        &amp;lt;types&amp;gt;\par ??          &amp;lt;type \cf3 type\cf1 ="\cf4 UnitySamples.ILogger,UnitySamples\cf1 "\par ??                \cf3 mapTo\cf1 ="\cf4 UnitySamples.ConsoleLogger,UnitySamples\cf1 " \par ??                \cf3 lifetime\cf1 ="\cf4 Singleton\cf1 "/&amp;gt;\par ??        &amp;lt;/types&amp;gt;\par ??      &amp;lt;/container&amp;gt;\par ??    &amp;lt;/containers&amp;gt;\par ??  &amp;lt;/unity&amp;gt;\par ??&amp;lt;/configuration&amp;gt;}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;?xml &lt;span style="color: rgb(255, 128, 0);"&gt;version&lt;/span&gt;="&lt;span style="color: lime;"&gt;1.0&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;encoding&lt;/span&gt;="&lt;span style="color: lime;"&gt;utf-8&lt;/span&gt;" ?&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;configuration&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;configSections&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;section &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;unity&lt;/span&gt;"&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;             &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: lime;"&gt;                   Microsoft.Practices.Unity.Configuration&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;/configSections&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;unity&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;containers&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;container&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &amp;lt;types&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;          &amp;lt;type &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnitySamples.ILogger,UnitySamples&lt;/span&gt;"&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;mapTo&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnitySamples.ConsoleLogger,UnitySamples&lt;/span&gt;" &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: rgb(255, 128, 0);"&gt;lifetime&lt;/span&gt;="&lt;span style="color: lime;"&gt;Singleton&lt;/span&gt;"/&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &amp;lt;/types&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;/container&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/containers&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;/unity&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Now, let's do the same thing with Castle Windsor.  Most of the code will be the same from our Unity sample as I can't imagine that much will change except that I don't need to register the DependencyAttribute on the CustomerTasks object.  Let's first look at the changed CustomerTasks object.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  CastleSamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 CustomerTasks\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf5 ILogger\cf3  logger = \cf1 new\cf3  \cf4 NullLogger\cf3 ();\par ??\par ??        \cf1 public\cf3  \cf5 ILogger\cf3  Logger\par ??        \{\par ??            \cf1 get\cf3  \{ \cf1 return\cf3  logger; \}\par ??            \cf1 set\cf3  \{ logger = \cf1 value\cf3 ; \}\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SaveCustomer()\par ??        \{\par ??            Logger.Log(\cf6 "Saved customer"\cf3 );\par ??        \}\par ??    \}\par ??\}}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; CastleSamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; logger = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;NullLogger&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; Logger&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; logger; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;set&lt;/span&gt; { logger = &lt;span style="color: rgb(255, 128, 0);"&gt;value&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; SaveCustomer()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            Logger.Log(&lt;span style="color: lime;"&gt;"Saved customer"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Now, let's look at the program.cs file to see how really nothing changed at all from our perspective:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  Castle.Windsor;\par ??\cf1 using\cf3  Castle.Windsor.Configuration.Interpreters;\par ??\par ??\cf1 namespace\cf3  CastleSamples\par ??\{\par ??    \cf1 class\cf3  \cf4 Program\par ??\cf3     \{\par ??        \cf1 static\cf3  \cf1 void\cf3  Main(\cf1 string\cf3 [] args)\par ??        \{\par ??            \cf4 WindsorContainer\cf3  container = \cf1 new\cf3  \cf4 WindsorContainer\cf3 (\cf1 new\cf3  \cf4 XmlInterpreter\cf3 ());\par ??            \cf4 CustomerTasks\cf3  tasks1 = container.Resolve&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            \cf4 CustomerTasks\cf3  tasks2 = container.Resolve&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            tasks1.SaveCustomer();\par ??            tasks2.SaveCustomer();\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Castle.Windsor;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Castle.Windsor.Configuration.Interpreters;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; CastleSamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Program&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;WindsorContainer&lt;/span&gt; container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;WindsorContainer&lt;/span&gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;XmlInterpreter&lt;/span&gt;());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks1 = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks2 = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks1.SaveCustomer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks2.SaveCustomer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And then our config file looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 &amp;lt;?xml \cf3 version\cf1 ="\cf4 1.0\cf1 " \cf3 encoding\cf1 ="\cf4 utf-8\cf1 " ?&amp;gt;\par ??&amp;lt;configuration&amp;gt;\par ??  &amp;lt;configSections&amp;gt;\par ??    &amp;lt;section \cf3 name\cf1 ="\cf4 castle\cf1 "\par ??        \cf3 type\cf1 ="\cf4 Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor\cf1 " /&amp;gt;\par ??  &amp;lt;/configSections&amp;gt;\par ??  &amp;lt;castle&amp;gt;\par ??    &amp;lt;components&amp;gt;\par ??      &amp;lt;component \cf3 id\cf1 ="\cf4 customertasks\cf1 " \cf3 type\cf1 ="\cf4 CastleSamples.CustomerTasks, CastleSamples\cf1 " \cf3 lifestyle\cf1 ="\cf4 transient\cf1 " /&amp;gt;\par ??      &amp;lt;component \cf3 id\cf1 ="\cf4 logger.console\cf1 " \cf3 service\cf1 ="\cf4 CastleSamples.ILogger, CastleSamples\cf1 " \cf3 type\cf1 ="\cf4 CastleSamples.ConsoleLogger, CastleSamples\cf1 " \cf3 lifestyle\cf1 ="\cf4 singleton\cf1 " /&amp;gt;\par ??    &amp;lt;/components&amp;gt;\par ??  &amp;lt;/castle&amp;gt;\par ??&amp;lt;/configuration&amp;gt;}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;?xml &lt;span style="color: rgb(255, 128, 0);"&gt;version&lt;/span&gt;="&lt;span style="color: lime;"&gt;1.0&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;encoding&lt;/span&gt;="&lt;span style="color: lime;"&gt;utf-8&lt;/span&gt;" ?&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;configuration&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;configSections&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;section &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;castle&lt;/span&gt;"&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;/configSections&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;castle&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;components&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;component &lt;span style="color: rgb(255, 128, 0);"&gt;id&lt;/span&gt;="&lt;span style="color: lime;"&gt;customertasks&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;CastleSamples.CustomerTasks, CastleSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;lifestyle&lt;/span&gt;="&lt;span style="color: lime;"&gt;transient&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;component &lt;span style="color: rgb(255, 128, 0);"&gt;id&lt;/span&gt;="&lt;span style="color: lime;"&gt;logger.console&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;service&lt;/span&gt;="&lt;span style="color: lime;"&gt;CastleSamples.ILogger, CastleSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;CastleSamples.ConsoleLogger, CastleSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;lifestyle&lt;/span&gt;="&lt;span style="color: lime;"&gt;singleton&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/components&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;/castle&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;/configuration&amp;gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
So, in reality, nothing changed from our constructor injection versus our setter injection implementation for Castle Windsor.  That to me is pretty cool...  But, now, let's move our attention to StructureMap.  Let's walk through only the code that has changed.  I'm only going to use the one with the StructureMap.config file and not the fluent interfaces just yet.  I know more of the config file and not enough of the interfaces to be effective.  Let's go through what really changed.  In reality, everything is the same from the Castle Windsor implementation and the StructureMap one except for the Program.cs and the StructureMap.config file, so let's look at the Program.cs first.&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  StructureMap;\par ??\par ??\cf1 namespace\cf3  StructureMapSamples\par ??\{\par ??    \cf1 class\cf3  \cf4 Program\par ??\cf3     \{\par ??        \cf1 static\cf3  \cf1 void\cf3  Main(\cf1 string\cf3 [] args)\par ??        \{\par ??            \cf4 CustomerTasks\cf3  tasks1 = \cf4 ObjectFactory\cf3 .GetInstance&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            \cf4 CustomerTasks\cf3  tasks2 = \cf4 ObjectFactory\cf3 .GetInstance&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            tasks1.SaveCustomer();\par ??            tasks2.SaveCustomer();   \par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; StructureMap;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; StructureMapSamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Program&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks1 = &lt;span style="color: yellow;"&gt;ObjectFactory&lt;/span&gt;.GetInstance&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks2 = &lt;span style="color: yellow;"&gt;ObjectFactory&lt;/span&gt;.GetInstance&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks1.SaveCustomer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks2.SaveCustomer();   &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
And to make sure our object is a singleton, let's make our StructureMap.config file and walk through the details:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green255\blue255;\red40\green40\blue40;\red255\green128\blue0;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 &amp;lt;?xml \cf3 version\cf1 ="\cf4 1.0\cf1 " \cf3 encoding\cf1 ="\cf4 utf-8\cf1 " ?&amp;gt;\par ??&amp;lt;StructureMap&amp;gt;\par ??  &amp;lt;PluginFamily \cf3 Type\cf1 ="\cf4 StructureMapSamples.ILogger\cf1 " \cf3 Assembly\cf1 ="\cf4 StructureMapSamples\cf1 " \cf3 DefaultKey\cf1 ="\cf4 Console\cf1 "&amp;gt;\par ??    &amp;lt;Interceptors&amp;gt;\par ??      &amp;lt;Interceptor \cf3 Type\cf1 ="\cf4 Singleton\cf1 " /&amp;gt;\par ??    &amp;lt;/Interceptors&amp;gt;\par ??    &amp;lt;Plugin \cf3 Assembly\cf1 ="\cf4 StructureMapSamples\cf1 " \cf3 Type\cf1 ="\cf4 StructureMapSamples.ConsoleLogger\cf1 " \cf3 ConcreteKey\cf1 ="\cf4 Console\cf1 " /&amp;gt;\par ??    &amp;lt;/PluginFamily&amp;gt;\par ??  &amp;lt;PluginFamily \cf3 Type\cf1 ="\cf4 StructureMapSamples.CustomerTasks\cf1 " \cf3 Assembly\cf1 ="\cf4 StructureMapSamples\cf1 " \cf3 DefaultKey\cf1 ="\cf4 CustomerTasks\cf1 "&amp;gt;\par ??    &amp;lt;Plugin \cf3 Assembly\cf1 ="\cf4 StructureMapSamples\cf1 " \cf3 Type\cf1 ="\cf4 StructureMapSamples.CustomerTasks\cf1 " \cf3 ConcreteKey\cf1 ="\cf4 CustomerTasks\cf1 "&amp;gt;\par ??      &amp;lt;Setter \cf3 Name\cf1 ="\cf4 Logger\cf1 " \cf3 Key\cf1 ="\cf4 Console\cf1 " /&amp;gt;\par ??    &amp;lt;/Plugin&amp;gt;\par ??  &amp;lt;/PluginFamily&amp;gt;\par ??&amp;lt;/StructureMap&amp;gt;}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;?xml &lt;span style="color: rgb(255, 128, 0);"&gt;version&lt;/span&gt;="&lt;span style="color: lime;"&gt;1.0&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;encoding&lt;/span&gt;="&lt;span style="color: lime;"&gt;utf-8&lt;/span&gt;" ?&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;StructureMap&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;PluginFamily &lt;span style="color: rgb(255, 128, 0);"&gt;Type&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples.ILogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Assembly&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;DefaultKey&lt;/span&gt;="&lt;span style="color: lime;"&gt;Console&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;Interceptors&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;Interceptor &lt;span style="color: rgb(255, 128, 0);"&gt;Type&lt;/span&gt;="&lt;span style="color: lime;"&gt;Singleton&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/Interceptors&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;Plugin &lt;span style="color: rgb(255, 128, 0);"&gt;Assembly&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Type&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples.ConsoleLogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;ConcreteKey&lt;/span&gt;="&lt;span style="color: lime;"&gt;Console&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/PluginFamily&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;PluginFamily &lt;span style="color: rgb(255, 128, 0);"&gt;Type&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples.CustomerTasks&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Assembly&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;DefaultKey&lt;/span&gt;="&lt;span style="color: lime;"&gt;CustomerTasks&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;Plugin &lt;span style="color: rgb(255, 128, 0);"&gt;Assembly&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Type&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples.CustomerTasks&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;ConcreteKey&lt;/span&gt;="&lt;span style="color: lime;"&gt;CustomerTasks&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;Setter &lt;span style="color: rgb(255, 128, 0);"&gt;Name&lt;/span&gt;="&lt;span style="color: lime;"&gt;Logger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Key&lt;/span&gt;="&lt;span style="color: lime;"&gt;Console&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/Plugin&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;  &amp;lt;/PluginFamily&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;/StructureMap&amp;gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
If you're familiar with StructureMap, the config file should make sense to you as I'm creating an ILogger with the default implementation being the ConsoleLogger and then we make sure it is a singleton through the use of an interceptor.  Then we also do a setter injection through our plugin of the CustomerTasks with setting the Logger property to the key of Console.  Pretty simple and straightforward.&lt;br /&gt;
&lt;br /&gt;
So, as you can see, they are very similar in nature, but attack the problem in different ways.  That's the beauty of it all, just determine your needs and your programming style and then the pick of your IoC container should come into line with that.  These are pretty simple and naive samples, but I just want to whet your appetite to open your mind and look for yourself at these containers for yourself.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;AOP with PostSharp and Unity?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Gael Fraiteur recently posted on the altdotnet list about the new release of &lt;a href="http://www.postsharp.org/download/"&gt;PostSharp&lt;/a&gt;.  Gael blogged about that &lt;a href="http://www.postsharp.org/blog/2008/02/announcing-postsharp-10-rc-2.html"&gt;here&lt;/a&gt;.  A couple of things intrigued me about it, including the license change to LGPL for the runtime and GPL for the code.  This requires a commercial license should you want to redistribute it with your application.  But, I'll leave that up to him and the lawyers to figure out.  &lt;br /&gt;
&lt;br /&gt;
But, let's get back to Unity for just a second.  Gael recently announced on the Unity Application Block discussion list about including an extension to support PostSharp which you can find &lt;a href="http://www.codeplex.com/unity/Thread/View.aspx?ThreadId=22764"&gt;here&lt;/a&gt;.  You can find the code in particular to do this, plus the Stoplight sample converted at GoogleCode &lt;a href="http://code.google.com/p/postsharp-user-plugins/"&gt;here&lt;/a&gt; under PostSharp4Unity.  Get your favorite SVN client and pull it down.&lt;br /&gt;
&lt;br /&gt;
So, let's take my basic example from above and try to get it using the default constructors instead of the approach of calling the container to get ourselves an instance.  A good approach is to keep the container out of your way and produce cleaner code.  A downside of using IoC containers is that they can litter up your code.  PostSharp4Unity allows us to create an extension for Unity and use our default constructors.&lt;br /&gt;
&lt;br /&gt;
First, let's create a Unity container provider so that we can initialize our container programmatically.  Create a UnityContainerProvider in your project that inherits from the IUnityContainerProvider.  That code should look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 using\cf3  Microsoft.Practices.Unity;\par ??\cf1 using\cf3  PostSharp4Unity;\par ??\cf1 using\cf3  UnitySamples;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 sealed\cf3  \cf1 class\cf3  \cf4 UnityContainerProvider\cf3  : \cf5 IUnityContainerProvider\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf5 IUnityContainer\cf3  container;\par ??\par ??        \cf1 public\cf3  UnityContainerProvider()\par ??        \{\par ??            \cf1 this\cf3 .container = \cf1 new\cf3  \cf4 UnityContainer\cf3 ()\par ??                .Register&amp;lt;\cf5 ILogger\cf3 , \cf4 ConsoleLogger\cf3 &amp;gt;().SetSingleton&amp;lt;\cf5 ILogger\cf3 &amp;gt;();\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf5 IUnityContainer\cf3  CurrentContainer\par ??        \{\par ??            \cf1 get\cf3  \{ \cf1 return\cf3  \cf1 this\cf3 .container; \}\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; PostSharp4Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; UnitySamples;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;sealed&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainerProvider&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainerProvider&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; container;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; UnityContainerProvider()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;this&lt;/span&gt;.container = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContainer&lt;/span&gt;()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                .Register&amp;lt;&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;, &lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;ContainerControlledLifetimeManager&lt;/span&gt;&lt;span style="color: yellow;"&gt;&lt;/span&gt;());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IUnityContainer&lt;/span&gt; CurrentContainer&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;this&lt;/span&gt;.container; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Now we also have to mark our assemblyinfo.cs with our default UnityProviderContainer, so open up your assemblyinfo.cs and put this info in there:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  PostSharp4Unity;\par ??\cf1 using\cf3  UnitySamples;\par ??\par ??[\cf1 assembly\cf3 : \cf4 DefaultUnityContainerProvider\cf3 (\cf1 typeof\cf3 (\cf4 UnityContainerProvider\cf3 ))]}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; PostSharp4Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; UnitySamples;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;[&lt;span style="color: rgb(255, 128, 0);"&gt;assembly&lt;/span&gt;: &lt;span style="color: yellow;"&gt;DefaultUnityContainerProvider&lt;/span&gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: yellow;"&gt;UnityContainerProvider&lt;/span&gt;))]&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
Ok, done and now we have to mark our class that we want to mark our configurable objects that we want to control with PostSharp.  So, open CustomerTasks and modify it to this:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;\red43\green145\blue175;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2 using\cf3  Microsoft.Practices.Unity;\par ??\cf1 using\cf3  PostSharp4Unity;\par ??\par ??\cf1 namespace\cf3  UnitySamples\par ??\{\par ??    [\cf4 Configurable\cf3 ]\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 CustomerTasks\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf5 ILogger\cf3  logger = \cf1 new\cf3  \cf4 NullLogger\cf3 ();\par ??\par ??        [\cf4 Dependency\cf3 ]\par ??        \cf1 public\cf3  \cf5 ILogger\cf3  Logger\par ??        \{\par ??            \cf1 get\cf3  \{ \cf1 return\cf3  logger; \}\par ??            \cf1 set\cf3  \{ logger = \cf1 value\cf3 ; \}\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SaveCustomer()\par ??        \{\par ??            Logger.Log(\cf6 "Saved customer"\cf3 );\par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Microsoft.Practices.Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; PostSharp4Unity;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    [&lt;span style="color: yellow;"&gt;Configurable&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; logger = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;NullLogger&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        [&lt;span style="color: yellow;"&gt;Dependency&lt;/span&gt;]&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt; Logger&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt; { &lt;span style="color: rgb(255, 128, 0);"&gt;return&lt;/span&gt; logger; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;set&lt;/span&gt; { logger = &lt;span style="color: rgb(255, 128, 0);"&gt;value&lt;/span&gt;; }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; SaveCustomer()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            Logger.Log(&lt;span style="color: lime;"&gt;"Saved customer"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
So, then our program.cs can look like this now:&lt;br /&gt;
&lt;br /&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Monaco;}}{\colortbl;??\red255\green128\blue0;\red40\green40\blue40;\red255\green255\blue255;\red255\green255\blue0;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 class\cf3  \cf4 Program\par ??\cf3     \{\par ??        \cf1 static\cf3  \cf1 void\cf3  Main(\cf1 string\cf3 [] args)\par ??        \{\par ??            \cf4 CustomerTasks\cf3  tasks1 = \cf1 new\cf3  \cf4 CustomerTasks\cf3 ();\par ??            \cf4 CustomerTasks\cf3  tasks2 = \cf1 new\cf3  \cf4 CustomerTasks\cf3 ();\par ??            tasks1.SaveCustomer();\par ??            tasks2.SaveCustomer();   \par ??        \}\par ??    \}\par ??\}\par ??}
--&gt;
&lt;div style="background: rgb(40, 40, 40) none repeat scroll 0% 50%; font-family: Monaco; font-size: 8pt; color: white; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;namespace&lt;/span&gt; UnitySamples&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;{&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Program&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &lt;span style="color: rgb(255, 128, 0);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;[] args)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks1 = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks2 = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks1.SaveCustomer();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks2.SaveCustomer();   &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    }&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
But, in order for PostSharp to do its magic, we need to make sure it's part of our compilation targets in our .csproj file.  So, I hand munged mine and got it to work like this:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/PropertyGroup&amp;gt;&lt;br /&gt;
  &amp;lt;Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /&amp;gt;&lt;br /&gt;
  &amp;lt;Import Project="$(PostSharpDirectory)PostSharp.targets" Condition=" Exists('$(PostSharpDirectory)PostSharp.targets') " /&amp;gt;&lt;br /&gt;
&amp;lt;/Project&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then I'm able to get the magic of PostSharp to do its work.  Pretty slick!&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Wrapping It Up&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, I hopefully whetted your appetite for these IoC containers for you to go and do a comparison on your own.  Each container has a different way of configuring itself and each solves a different problem set.  It's up to you to decide which one to use.  Along the way you can have a pretty cool journey though in learning deciding what works for you and what doesn't.  Until next time, and hopefully an F# related post... &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120002"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120002" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/120002.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx</guid>
            <pubDate>Wed, 27 Feb 2008 00:31:34 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120002.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120002.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120002.aspx</trackback:ping>
        </item>
        <item>
            <title>Fluency in Fluent Interfaces</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/02/01/119215.aspx</link>
            <description>&lt;a href="http://www.hanselman.com/blog"&gt;Scott Hanselman's&lt;/a&gt; recent post about the &lt;a href="http://www.hanselman.com/blog/TheWeeklySourceCode14FluentInterfaceEdition.aspx"&gt;Daily Source Code 14 - Fluent Interface Edition&lt;/a&gt; got me to think more on &lt;a href="http://martinfowler.com/bliki/FluentInterface.html"&gt;fluent interfaces&lt;/a&gt; and a previous post of mine on &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/08/118362.aspx"&gt;ObjectMother versus Test Data Builders&lt;/a&gt;.  Also, it comes to mind in regards to DSLs, both internal and external that has me intrigued.  Partially due to my latest involvement with Ruby and F#.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Test Data Builder Example&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, let's revisit that simple example:&lt;br /&gt;
&lt;br /&gt;
public class ClaimBuilder&lt;br /&gt;
{&lt;br /&gt;
     private DateTime claimDate;&lt;br /&gt;
     private Provider provider = ProviderBuilder.StartRecording().Build();&lt;br /&gt;
     private Recipient recipient = RecipientBuilder.StartRecording().Build();&lt;br /&gt;
     private ClaimLineCollection claimLines = ClaimLinesBuilder.StartRecording.Build();&lt;br /&gt;
&lt;br /&gt;
     public static ClaimBuilder StartRecording()&lt;br /&gt;
     {&lt;br /&gt;
          return new ClaimBuilder();&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     public ClaimBuilder WithClaimDate(DateTime claimDate)&lt;br /&gt;
     {&lt;br /&gt;
          this.claimDate = claimDate;&lt;br /&gt;
          return this;&lt;br /&gt;
     }&lt;br /&gt;
     &lt;br /&gt;
     public ClaimBuilder WithProvider(Provider provider)&lt;br /&gt;
     {&lt;br /&gt;
          this.provider = provider;&lt;br /&gt;
          return this;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     public ClaimBuilder WithRecipient(Recipient recipient)&lt;br /&gt;
     {&lt;br /&gt;
          this.recipient = recipient;&lt;br /&gt;
          return this;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     public ClaimBuilder WithClaimLines(ClaimLineCollection claimLines)&lt;br /&gt;
     {&lt;br /&gt;
          this.claimLines = claimLines;&lt;br /&gt;
          return this;&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     public static implicit operator Claim(ClaimBuilder builder)&lt;br /&gt;
     {&lt;br /&gt;
          return new Claim(builder.claimDate, builder.provider, builder.recipient, builder.claimLines);&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
As you may note I changed the Build method from the previous post to an implicit operator to save me some coding time when it comes to my builders.  This is one of the very very few places where I'd recommend using this operator.  Anyhow, then we'd have the calling code to look similar to this for my unit tests.&lt;br /&gt;
&lt;br /&gt;
Claim claim = ClaimBuilder.StartRecording()&lt;br /&gt;
     .WithClaimDate(new DateTime(2008, 1, 1))&lt;br /&gt;
     .WithProvider(ProviderBuilder.StartRecording()&lt;br /&gt;
          .WithName("Robert", "Jones")&lt;br /&gt;
          .WithAddress(AddressBuilder.StartRecording()&lt;br /&gt;
               .WithStreetAddress("1800 28th St, NW")&lt;br /&gt;
               .WithCity("Washington")&lt;br /&gt;
               .WithState("DC"))))&lt;br /&gt;
     .WithRecipient(RecipientBuilder.StartRecording()&lt;br /&gt;
          .WithName(James", "Smith")&lt;br /&gt;
          .WithAddress(AddressBuilder.StartRecording()&lt;br /&gt;
               .WithStreetAddress("1210 14th St, SE",)&lt;br /&gt;
               .WithCity("Washington")&lt;br /&gt;
               .WithState("DC"))))&lt;br /&gt;
     .WithClaimLines(ClaimLinesBuilder.StartRecording()&lt;br /&gt;
          .WithClaim("00308-1")));&lt;br /&gt;
&lt;br /&gt;
This is truly powerful here to make it make sense to the reader instead of the usual black box ObjectMother approach.  When building my entity objects for test, this is the main approach I use.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Other Examples&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Scott Bellware has introduced the &lt;a href="http://code.google.com/p/nunit-spec/"&gt;Behavior Driven Development NUnit Extensions&lt;/a&gt; which makes heavy use of fluent interfaces.  With my deeper dive into BDD, this has been very helpful.  &lt;a href="http://codebetter.com/blogs/david_laribee/archive/2007/12/17/approaching-bdd.aspx"&gt;Dave Laribee&lt;/a&gt; also has me on the kick as well, so lots of thanks to them for pointing me in the right direction, although some may disagree with their directions.  But that's for another time and another post.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://codebetter.com/blogs/jeremy.miller/default.aspx"&gt;Jeremy Miller&lt;/a&gt; also has fluent interfaces on his &lt;a href="http://structuremap.sourceforge.net/"&gt;StructureMap &lt;/a&gt;IOC container project.   Some new parts with registration will be coming up with his new release of version 2.5 as noted &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/01/23/some-new-ways-to-build-objects-in-structuremap-with-less-configuration.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Of course I can keep rattling on with others like NHibernate and the ICriteria, Castle Windsor's fluent registration interfaces and so on.  The list goes on!  Very cool stuff coming out lately...  Until next time!
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/01/119215.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/01/119215.aspx" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119215"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119215" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/Podwysocki/aggbug/119215.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/02/01/119215.aspx</guid>
            <pubDate>Fri, 01 Feb 2008 23:47:41 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/119215.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/02/01/119215.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/119215.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/119215.aspx</trackback:ping>
        </item>
    </channel>
</rss>