<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>C#</title>
        <link>http://geekswithblogs.net/Podwysocki/category/4491.aspx</link>
        <description>C#</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>Adventures in F# - F# 101 Part 8 (Mutables and Reference Cells)</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/04/15/121272.aspx</link>
            <description>Time for another adventure in F#, covering some of the basics of functional programming and F# in particular.  Today we'll manage to look more at regular .NET integration and .NET programming.  With the previous efforts, we've looked more at &lt;a href="http://en.wikipedia.org/wiki/Functional_programming"&gt;functional programming&lt;/a&gt; and in turn F# specific things, but want to show that you can do anything normally in F# that you can in C#.  To me, F# is the perfect all-purpose language because it can do a lot of the things C# can do, but in turn, F# can do things much more elegantly than C# can, such as &lt;a href="http://en.wikipedia.org/wiki/Pattern_matching"&gt;Pattern Matching&lt;/a&gt;.&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 catch up to where we are today:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a mce_href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-1.aspx" href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-1.aspx"&gt;Part 1 - Basic functional programming&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a mce_href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-2.aspx" href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-2.aspx"&gt;Part 2 - Currying and Tuples&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a mce_href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-3.aspx" href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-3.aspx"&gt;Part 3 - Scope, Recursion and Anonymous Functions&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a mce_href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-4.aspx" href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-4.aspx"&gt;Part 4 - History of F#, Operators and Lists&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a mce_href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-5-pattern-matching.aspx" href="http://weblogs.asp.net/podwysocki/archive/2008/03/17/adventures-in-f-f-101-part-5-pattern-matching.aspx"&gt;Part 5 - Pattern Matching&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/21/adventures-in-f-f-101-part-6-lazy-evaluation.aspx"&gt;Part 6 - Lazy Evaluation&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/04/02/adventures-in-f-f-101-part-7-creating-types.aspx"&gt;Part 7 - Creating Types&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
Today's topic will be covering imperative and object oriented programming in F#.  There is a lot to cover, so let's get started.  But there are a few administrative things to get out of the way first.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Learning F# ala Ted Neward?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.tedneward.com/"&gt;Ted Neward&lt;/a&gt; recently announced on &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=332"&gt;DotNetRocks Episode 332&lt;/a&gt;  that he's in the process of creating a class for F# for &lt;a href="http://www.pluralsight.com/"&gt;Pluralsight&lt;/a&gt;.  That should be interesting to those who are interested in this series, as well as F# in general.  Right now the community is rather small, so efforts like this should be rather rewarding I would hope.  Ted's a pretty brilliant guy, so I'd imagine only the best.  I'm hoping more details come out soon.  &lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Pattern Matching in C#&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Part of this series is intended to bring such concepts as Pattern Matching, &lt;a href="http://en.wikipedia.org/wiki/Currying"&gt;Currying&lt;/a&gt; and other Functional Programming concepts to the C# developer.  After all, the more C# language evolves, the more it seems to fall into the Functional Programming category.  In previous posts, I showed how to relate currying to C# and it was less elegant than F# to say the least.&lt;br /&gt;
&lt;br /&gt;
But, let's look at Pattern Matching.  &lt;a href="http://community.bartdesmet.net/blogs/bart/"&gt;Bart De Smet&lt;/a&gt; has been posting recently on his blog about bringing the beauty of pattern matching to C#.  So far it's been a good six posts into it and I urge you to go ahead and take a look at this series.  &lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/06/pattern-matching-in-c-part-0.aspx"&gt;Pattern Matching in C# - Part 0&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/07/pattern-matching-in-c-part-1.aspx"&gt;Pattern Matching in C# - Part 1&lt;/a&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/06/pattern-matching-in-c-part-0.aspx"&gt;&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/08/pattern-matching-in-c-part-2.aspx"&gt;Pattern Matching in C# - Part 2&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/09/pattern-matching-in-c-part-3.aspx"&gt;Pattern Matching in C# - Part 3&lt;/a&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/06/pattern-matching-in-c-part-0.aspx"&gt;&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/10/pattern-matching-in-c-part-4.aspx"&gt;Pattern Matching in C# - Part 4&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/11/pattern-matching-in-c-part-5.aspx"&gt;Pattern Matching in C# - Part 5&lt;br /&gt;
    &lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/14/pattern-matching-in-c-part-6.aspx"&gt;Pattern Matching in C# - Part 6&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/04/15/pattern-matching-in-c-part-7.aspx"&gt;Pattern Matching in C# - Part 7&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
But when you read the series, it's all about getting into the low level and compiling expression trees to make the same simple beauty that is F#.  Sure, it can be done in C#, but nowhere near as elegant.  Performance is another issue that comes to mind with these.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Imperative Programming in F#&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This section I'll lay out some of the basics of imperative style programming before I get into the full object oriented approach to programming.  So, we'll cover just a few topics and then I'll feel comfortable moving onto the real parts of creating classes and such.  We'll cover such things as void types and mutability in this section.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;The unit Type&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
One of the first things I forgot to mention when describing F# functions and values in the unit type.  Think of this as the void type in C# that you are used to.  It's the type that doesn't accept or return a value.  First, let's look at the typical C# program with the void type for Hello World.&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;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2     \cf3 class\cf1  \cf4 Program\par ??\cf1     \{\par ??        \cf3 static\cf1  \cf3 void\cf1  Main(\cf3 string\cf1 [] args)\par ??        \{\par ??            \cf4 Console\cf1 .WriteLine(\cf5 "Hello World"\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;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;Console&lt;/span&gt;.WriteLine(&lt;span style="color: lime;"&gt;"Hello World"&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;
Now, let's go ahead and look at it from the F# perspective. &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;
&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;main() =&lt;br /&gt;
  printfn &lt;span style="color: rgb(0, 255, 0);"&gt;"Hello World"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
main()&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
As you will see when you hover over our code is that it is a unit type.  That in itself isn't all that interesting.   But, what we'll run into is problems when functions return a value, but we're not all that interested in them.  What happens?  Well, F# will complain that your return value isn't compatible with the unit type, which is essentially true.  So, how do you get around that?  Let's walk through a simple unit test of a Stack written in F# and unit testing with the &lt;a href="http://codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; framework.&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:\Tools\xunit-build-1252\xunit.dll"&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 153, 0);"&gt;open &lt;/span&gt;System&lt;br /&gt;
&lt;span style="color: rgb(255, 153, 0);"&gt;open &lt;/span&gt;System.Collections.Generic&lt;br /&gt;
&lt;span style="color: rgb(255, 153, 0);"&gt;open &lt;/span&gt;Xunit&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 153, 0);"&gt;type &lt;/span&gt;Stack&amp;lt;'t&amp;gt; = &lt;span style="color: rgb(255, 153, 0);"&gt;class&lt;/span&gt;&lt;br /&gt;
  &lt;span style="color: rgb(255, 153, 0);"&gt;val &lt;/span&gt;elements : LinkedList&amp;lt;'t&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
  &lt;span style="color: rgb(255, 153, 0);"&gt;new&lt;/span&gt;() = { elements = &lt;span style="color: rgb(255, 153, 0);"&gt;new &lt;/span&gt;LinkedList&amp;lt;'t&amp;gt;() }&lt;br /&gt;
 &lt;br /&gt;
  &lt;span style="color: rgb(255, 153, 0);"&gt;member &lt;/span&gt;x.IsEmpty&lt;br /&gt;
    &lt;span style="color: rgb(255, 153, 0);"&gt;with &lt;/span&gt;get() = x.elements.Count = 0&lt;br /&gt;
   &lt;br /&gt;
  &lt;span style="color: rgb(255, 153, 0);"&gt;member &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, 153, 0);"&gt;member &lt;/span&gt;x.Top&lt;br /&gt;
    &lt;span style="color: rgb(255, 153, 0);"&gt;with &lt;/span&gt;get() =&lt;br /&gt;
      &lt;span style="color: rgb(255, 153, 0);"&gt;if &lt;/span&gt;x.elements.Count = 0 &lt;span style="color: rgb(255, 153, 0);"&gt;then&lt;/span&gt;&lt;br /&gt;
        raise (InvalidOperationException("cannot top an empty stack"))&lt;br /&gt;
      x.elements.First.Value&lt;br /&gt;
     &lt;br /&gt;
  &lt;span style="color: rgb(255, 153, 0);"&gt;member &lt;/span&gt;x.Pop() =&lt;br /&gt;
    let top = x.Top&lt;br /&gt;
    x.elements.RemoveFirst()&lt;br /&gt;
    top&lt;br /&gt;
&lt;span style="color: rgb(255, 153, 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;PopEmpty () =&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 = &lt;span style="color: rgb(255, 153, 0);"&gt;new&lt;/span&gt; Stack&amp;lt;string&amp;gt;()&lt;br /&gt;
  Assert.Throws&amp;lt;InvalidOperationException&amp;gt;(&lt;span style="color: rgb(255, 153, 0);"&gt;fun &lt;/span&gt;() -&amp;gt; stack.Pop() |&amp;gt; ignore )&lt;br /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
The real interesting part you should pay attention to is the last line.  As you can see, I am using the forward operator to indicate that I really don't care what the function returns, just that I'm interested in that it executes.  This is most likely during such functions that have some sort of side effect to them.  I could also use the ignore function instead of the forward operator such as this:&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;[&amp;lt;Fact&amp;gt;]  &lt;br /&gt;
&lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;PopEmpty () =&lt;br /&gt;
  &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;stack &lt;span style="color: rgb(255, 153, 0);"&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;=&lt;/span&gt; new &lt;/span&gt;Stack&amp;lt;string&amp;gt;()&lt;br /&gt;
  Assert.Throws&amp;lt;InvalidOperationException&amp;gt;(&lt;span style="color: rgb(255, 153, 0);"&gt;fun &lt;/span&gt;() -&amp;gt; ignore(stack.Pop()) )&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
This is very helpful in these cases where we really don't care about the return value, instead want to mutate the state of our given object, such as removing a value from a collection and so on.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Mutables&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As I said in many posts before, by default all "variables" by which I mean values in F# are immutable.  This is a standard in functional programming and all in the ML family.  You can easily redefine a value by using the let keyword, but not actually mutate its state.  But, since F# is a multi-purpose language on the .NET platform, mutable state can be had.  To take advantage of this, mark your value as mutable.  Then to change the value, just use the &amp;lt;- operator to reassign the value.  Below is a simple example of this:&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;
&lt;span style="color: rgb(255, 153, 0);"&gt;let mutable&lt;/span&gt; answer = 42&lt;br /&gt;
printfn &lt;span style="color: rgb(0, 255, 0);"&gt;"Answer is %i"&lt;/span&gt; answer&lt;br /&gt;
answer &amp;lt;- 8&lt;br /&gt;
printfn &lt;span style="color: rgb(0, 255, 0);"&gt;"Answer is %i"&lt;/span&gt; answer&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
A key difference from the reassignment is that you cannot change the value type.  Whereas I can redefine answer by keep using the let keyword, I can only keep my answer in this above example of the int type.  &lt;br /&gt;
&lt;br /&gt;
This can also apply to record types as well where you can change the fields.  In the last installment, we talked about record types.  Well, by default there as well, the fields for the record type are immutable.  But, as with before, that can be changed.  I of course like to caution people that mutable state takes a lot of the value proposition away from the side effect free programming that you gain with F# by default.  But, nevertheless, you can still do it as noted below:&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;
&lt;span style="color: rgb(255, 153, 0);"&gt;type &lt;/span&gt;Person = { FirstName : string; &lt;span style="color: rgb(255, 153, 0);"&gt;mutable &lt;/span&gt;LastName : string; &lt;span style="color: rgb(255, 153, 0);"&gt;mutable &lt;/span&gt;IsMarried : bool }&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;friend = { FirstName = "Courtney"; LastName = "Cox"; IsMarried = &lt;span style="color: rgb(255, 153, 0);"&gt;false &lt;/span&gt;}&lt;br /&gt;
friend.LastName &amp;lt;- "Cox-Arquette"&lt;br /&gt;
friend.IsMarried &amp;lt;- true &lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
What I was able to do was define a Person record and change a couple of fields while using the &amp;lt;- operator and defining the fields as mutable.  Yes, I could have used some scientific calculation or something, but this was easy.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Reference Cells&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The last thing I want to touch on in this post is reference cells.  You can think of these much as pointers in other languages or reference types.  These of course can be of any type.  The idea behind using these is to make updating fields as easy as possible.  As with mutable fields, you cannot change the type once it has been assigned.  To use these, you need to remember three basic operators&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;ref &lt;/span&gt;- Allocates a reference cell&lt;/li&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;:=&lt;/span&gt; - Mutates a reference cell&lt;/li&gt;
    &lt;li&gt;&lt;span style="font-weight: bold;"&gt;!&lt;/span&gt; - Reads the reference cell&lt;br /&gt;
    &lt;/li&gt;
&lt;/ul&gt;
Below is a quick example of mutation through reference cells:&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;
&lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;x = ref 2&lt;br /&gt;
x := !x + 25&lt;br /&gt;
printfn &lt;span style="color: rgb(0, 255, 0);"&gt;"%i"&lt;/span&gt; !x&lt;br /&gt;
&lt;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
What the code example above lets me do is define a reference to the number 2.  Then I can change that reference by reading the current x value and adding 25.  Then I mutate the existing x value with the result.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is just meant to be a brief overview to some imperative programming constructs that you might see in .NET, Java, C, C++ and so on.  F# is a first class language all the way with constructs that support these things as well as your normal functional programming constructs.  I hope we get to cover some of this at &lt;a href="http://altdotnet.org/events/seattle"&gt;ALT.NET Open Spaces, Seattle&lt;/a&gt; at some point because I'm sure a lot of people will be interested.  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/15/121272.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/04/15/121272.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=121272"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121272" 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/121272.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/04/15/121272.aspx</guid>
            <pubDate>Wed, 16 Apr 2008 00:08:37 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/121272.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/04/15/121272.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/121272.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/121272.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>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>IoC and Unity - Configuration Changes for the Better</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/27/120808.aspx</link>
            <description>In my &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/25/ioc-and-unity-the-basics-and-interception.aspx"&gt;previous post&lt;/a&gt; about Unity and IoC containers, I made note of some changes in the latest drop of the Unity Application Block.  As &lt;a href="http://blogs.msdn.com/agile/"&gt;Grigori Melnik&lt;/a&gt;, the PM of the Unity and Enterprise Library team noted, &lt;a href="http://blogs.msdn.com/agile/archive/2008/03/20/unity-release-date-changes-to-april-7.aspx"&gt;Unity should be released&lt;/a&gt; in its final form on April 7th, so stay tuned.  In the mean time, the &lt;a href="http://www.codeplex.com/unity/Release/ProjectReleases.aspx?ReleaseId=11956"&gt;latest drop of Unity&lt;/a&gt; was on March 24th, so go ahead and it pick it up.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Configuration Changes&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As I noted from above, the public APIs really haven't changed all that much.  Instead, most of the efforts recently have been around performance improvements in the ObjectBuilder base and the configuration of the container itself.  I must admit that previous efforts left me a little cold with having to decorate my classes with the DependencyAttribute.  Well, you shouldn't have to do that anymore, now that the TypeInjectionElement has been added so that you can map your constructor arguments and so on.  Let's walk through a simple example of doing so.&lt;br /&gt;
&lt;br /&gt;
First, let's go through my basic anti-corruption container that I use for Unity and any other container that I use for registration and so on.&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;
Remember this is just a quick spike sample of my anti-corruption container which was taken from Ayende.  And then in order to configure my UnityContainer through the implementation of my IDependencyResolver interface.  Let's take a brief look at that:&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;
And then the implementation of the interface for Unity would 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;\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.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.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;
Now, if you look at the constructor for the UnityDependencyResolver above, I am using the default container in order to configure my container.  But, I have the option of specifying a name for it as well or even just an index.  I could just easily change that code to this and it would work if I name my container default.  This is a little bit of a change from before when I had to use the GetConfigCommand() method in order to configure the container which was a bit too chatty for my tastes. &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;\red0\green255\blue0;}??\fs16 \cf1\cb2\highlight2             container = \cf3 new\cf1  \cf4 UnityContainer\cf1 ();\par ??            \cf4 UnityConfigurationSection\cf1  section = (\cf4 UnityConfigurationSection\cf1 )\cf4 ConfigurationManager\cf1 .GetSection(\cf5 "unity"\cf1 );\par ??            section.Containers[\cf5 "default"\cf1 ].Configure(container);}
--&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;            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[&lt;span style="color: lime;"&gt;"default"&lt;/span&gt;].Configure(container);&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
So, the idea that I want to do is create an object graph so that I have classes with dependencies that have dependencies.  Without doing AOP and some basic interception, we could take the approach of keeping around something like an IContext which would have our cross-cutting concerns in one location such as logging and whatnot in one area so your objects don't sit there with 16 constructor parameters, and instead has a context from which it can pull.  This approach has worked for me in the past, so let's just go through that one right now.&lt;br /&gt;
&lt;br /&gt;
First, let's look at the context that has those cross-cutting concerns and the actual implementation:&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 IContext\par ??\cf3     \{\par ??        \cf4 ILogger\cf3  Logger \{ \cf1 get\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;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IContext&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; Logger { &lt;span style="color: rgb(255, 128, 0);"&gt;get&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;
And then the concrete implementation might look something like 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;}??\fs16 \cf1\cb2\highlight2 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 UnityContext\cf3  : \cf5 IContext\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf5 ILogger\cf3  logger;\par ??\par ??        \cf1 public\cf3  UnityContext(\cf5 ILogger\cf3  logger)\par ??        \{\par ??            \cf1 this\cf3 .logger = logger;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf5 ILogger\cf3  Logger\par ??        \{\par ??            \cf1 get\cf3  \{ \cf1 return\cf3  logger; \}\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;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityContext&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IContext&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;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;public&lt;/span&gt; UnityContext(&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;this&lt;/span&gt;.logger = logger;&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;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;/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 I do here is inject my logger into my context, and probably anything else that might be cross-cutting as well.  So, now in one of my classes, then I can accept the IContext in to do what I need it to do.  That would look something like 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 namespace\cf3  UnitySamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 Customer\par ??\cf3     \{\par ??        \cf1 public\cf3  \cf1 string\cf3  CustomerId \{ \cf1 get\cf3 ; \cf1 set\cf3 ; \}\par ??\par ??        \cf1 public\cf3  \cf1 string\cf3  FirstName \{ \cf1 get\cf3 ; \cf1 set\cf3 ; \}\par ??\par ??        \cf1 public\cf3  \cf1 string\cf3  MiddleName \{ \cf1 get\cf3 ; \cf1 set\cf3 ; \}\par ??\par ??        \cf1 public\cf3  \cf1 string\cf3  LastName \{ \cf1 get\cf3 ; \cf1 set\cf3 ; \}\par ??    \}\par ??\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 CustomerTasks\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf5 IContext\cf3  context;\par ??\par ??        \cf1 public\cf3  CustomerTasks(\cf5 IContext\cf3  context)\par ??        \{\par ??            \cf1 this\cf3 .context = context;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SaveCustomer(\cf4 Customer\cf3  customer)\par ??        \{\par ??            \cf6 // Save customer\par ??\cf3             context.Logger.LogEvent(\cf6 "Saving customer"\cf3 , \cf5 LogLevel\cf3 .Information);\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;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;Customer&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;string&lt;/span&gt; CustomerId { &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(255, 128, 0);"&gt;set&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;string&lt;/span&gt; FirstName { &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(255, 128, 0);"&gt;set&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;string&lt;/span&gt; MiddleName { &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(255, 128, 0);"&gt;set&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;string&lt;/span&gt; LastName { &lt;span style="color: rgb(255, 128, 0);"&gt;get&lt;/span&gt;; &lt;span style="color: rgb(255, 128, 0);"&gt;set&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;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(255, 128, 0);"&gt;readonly&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IContext&lt;/span&gt; context;&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; CustomerTasks(&lt;span style="color: rgb(43, 145, 175);"&gt;IContext&lt;/span&gt; context)&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;.context = context;&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;span style="color: yellow;"&gt;Customer&lt;/span&gt; customer)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: lime;"&gt;// Save customer&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            context.Logger.LogEvent(&lt;span style="color: lime;"&gt;"Saving customer"&lt;/span&gt;, &lt;span style="color: rgb(43, 145, 175);"&gt;LogLevel&lt;/span&gt;.Information);&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;
I'm not doing anything special, instead, just showing how this pattern might apply.  And then just tying it all together is my console application (sometimes my favorite UI for quick spikes).&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;\red0\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 IoC\cf3 .Initialize(\cf1 new\cf3  \cf4 UnityDependencyResolver\cf3 ());\par ??            \cf4 CustomerTasks\cf3  tasks = \cf4 IoC\cf3 .Resolve&amp;lt;\cf4 CustomerTasks\cf3 &amp;gt;();\par ??            tasks.SaveCustomer(\cf1 new\cf3  \cf4 Customer\cf3 \{ CustomerId = \cf5 "12345"\cf3 , FirstName = \cf5 "Joe"\cf3 , LastName = \cf5 "Smith"\cf3 , MiddleName = \cf5 "Frank"\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;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;IoC&lt;/span&gt;.Initialize(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;UnityDependencyResolver&lt;/span&gt;());&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt; tasks = &lt;span style="color: yellow;"&gt;IoC&lt;/span&gt;.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;CustomerTasks&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            tasks.SaveCustomer(&lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;Customer&lt;/span&gt;{ CustomerId = &lt;span style="color: lime;"&gt;"12345"&lt;/span&gt;, FirstName = &lt;span style="color: lime;"&gt;"Joe"&lt;/span&gt;, LastName = &lt;span style="color: lime;"&gt;"Smith"&lt;/span&gt;, MiddleName = &lt;span style="color: lime;"&gt;"Frank"&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;
But the more interesting part about this is the XML configuration.  I know many people such as Ayende have declared war on XML configuration, but I think for this quick example it does quite well.  If we start talking about complex object graphs, then I'd certainly agree and I'd rather do it programmatically.  But, let's first look at how I'd wire up the whole thing in the app.config file.&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 ??\tab &amp;lt;configSections&amp;gt;\par ??\tab \tab &amp;lt;section \cf3 name\cf1 ="\cf4 unity\cf1 " \cf3 type\cf1 ="\cf4 Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration\cf1 " /&amp;gt;\par ??\tab &amp;lt;/configSections&amp;gt;\par ??\par ??\tab &amp;lt;unity&amp;gt;\par ??\tab \tab &amp;lt;typeAliases&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 string\cf1 " \cf3 type\cf1 ="\cf4 System.String, mscorlib\cf1 " /&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 ILogger\cf1 " \cf3 type\cf1 ="\cf4 UnitySamples.ILogger, UnitySamples\cf1 " /&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 ConsoleLogger\cf1 " \cf3 type\cf1 ="\cf4 UnitySamples.ConsoleLogger, UnitySamples\cf1 " /&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 DebugLogger\cf1 " \cf3 type\cf1 ="\cf4 UnitySamples.DebugLogger, UnitySamples\cf1 " /&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 IContext\cf1 " \cf3 type\cf1 ="\cf4 UnitySamples.IContext, UnitySamples\cf1 " /&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 UnityContext\cf1 " \cf3 type\cf1 ="\cf4 UnitySamples.UnityContext, UnitySamples\cf1 " /&amp;gt;\par ??\tab \tab \tab &amp;lt;typeAlias \cf3 alias\cf1 ="\cf4 CustomerTasks\cf1 " \cf3 type\cf1 ="\cf4 UnitySamples.CustomerTasks, UnitySamples\cf1 " /&amp;gt;\par ??\tab \tab &amp;lt;/typeAliases&amp;gt;\par ??\tab \tab &amp;lt;containers&amp;gt;\par ??\tab \tab \tab &amp;lt;container&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;types&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;type \cf3 type\cf1 ="\cf4 ILogger\cf1 " \cf3 mapTo\cf1 ="\cf4 ConsoleLogger\cf1 " \cf3 name\cf1 ="\cf4 defaultLogger\cf1 "/&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;type \cf3 type\cf1 ="\cf4 ILogger\cf1 " \cf3 mapTo\cf1 ="\cf4 DebugLogger\cf1 " \cf3 name\cf1 ="\cf4 debugLogger\cf1 "/&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;type \cf3 type\cf1 ="\cf4 IContext\cf1 " \cf3 mapTo\cf1 ="\cf4 UnityContext\cf1 "&amp;gt;\par ??\tab \tab \tab \tab \tab \tab &amp;lt;typeConfig \cf3 extensionType\cf1 ="\cf4 Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration\cf1 "&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab &amp;lt;constructor&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab \tab &amp;lt;param \cf3 name\cf1 ="\cf4 logger\cf1 " \cf3 parameterType\cf1 ="\cf4 ILogger\cf1 "&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab \tab \tab &amp;lt;dependency \cf3 name\cf1 ="\cf4 debugLogger\cf1 "/&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab \tab &amp;lt;/param&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab &amp;lt;/constructor&amp;gt;\par ??\tab \tab \tab \tab \tab \tab &amp;lt;/typeConfig&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;/type&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;type \cf3 type\cf1 ="\cf4 CustomerTasks\cf1 "&amp;gt;\par ??\tab \tab \tab \tab \tab \tab &amp;lt;typeConfig \cf3 extensionType\cf1 ="\cf4 Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration\cf1 "&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab &amp;lt;constructor&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab \tab &amp;lt;param \cf3 name\cf1 ="\cf4 context\cf1 " \cf3 parameterType\cf1 ="\cf4 IContext\cf1 "&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab \tab \tab &amp;lt;dependency/&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab \tab &amp;lt;/param&amp;gt;\par ??\tab \tab \tab \tab \tab \tab \tab &amp;lt;/constructor&amp;gt;\par ??\tab \tab \tab \tab \tab \tab &amp;lt;/typeConfig&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;/type&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;/types&amp;gt;\par ??\tab \tab \tab &amp;lt;/container&amp;gt;\par ??\tab \tab &amp;lt;/containers&amp;gt;\par ??\tab &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;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, 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; &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;typeAliases&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&lt;/span&gt;="&lt;span style="color: lime;"&gt;string&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;System.String, mscorlib&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&lt;/span&gt;="&lt;span style="color: lime;"&gt;ILogger&lt;/span&gt;" &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;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&lt;/span&gt;="&lt;span style="color: lime;"&gt;ConsoleLogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnitySamples.ConsoleLogger, UnitySamples&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&lt;/span&gt;="&lt;span style="color: lime;"&gt;DebugLogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnitySamples.DebugLogger, UnitySamples&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&lt;/span&gt;="&lt;span style="color: lime;"&gt;IContext&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnitySamples.IContext, UnitySamples&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnityContext&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnitySamples.UnityContext, UnitySamples&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;typeAlias &lt;span style="color: rgb(255, 128, 0);"&gt;alias&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;UnitySamples.CustomerTasks, UnitySamples&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &amp;lt;/typeAliases&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;ILogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;mapTo&lt;/span&gt;="&lt;span style="color: lime;"&gt;ConsoleLogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;defaultLogger&lt;/span&gt;"/&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;ILogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;mapTo&lt;/span&gt;="&lt;span style="color: lime;"&gt;DebugLogger&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;debugLogger&lt;/span&gt;"/&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;IContext&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;mapTo&lt;/span&gt;="&lt;span style="color: lime;"&gt;UnityContext&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                        &amp;lt;typeConfig &lt;span style="color: rgb(255, 128, 0);"&gt;extensionType&lt;/span&gt;="&lt;span style="color: lime;"&gt;Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                            &amp;lt;constructor&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                &amp;lt;param &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;parameterType&lt;/span&gt;="&lt;span style="color: lime;"&gt;ILogger&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                    &amp;lt;dependency &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;debugLogger&lt;/span&gt;"/&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                &amp;lt;/param&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                            &amp;lt;/constructor&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                        &amp;lt;/typeConfig&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                    &amp;lt;/type&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;CustomerTasks&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                        &amp;lt;typeConfig &lt;span style="color: rgb(255, 128, 0);"&gt;extensionType&lt;/span&gt;="&lt;span style="color: lime;"&gt;Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                            &amp;lt;constructor&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                &amp;lt;param &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;context&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;parameterType&lt;/span&gt;="&lt;span style="color: lime;"&gt;IContext&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                    &amp;lt;dependency/&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                &amp;lt;/param&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                            &amp;lt;/constructor&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                        &amp;lt;/typeConfig&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                    &amp;lt;/type&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;
As you may notice from above, Unity gives us the ability to give type aliases so that we can reference the short names instead of the long ugly fully qualified type names by using the &amp;lt;typeAliases&amp;gt;&amp;lt;typeAlias&amp;gt; nodes in the configuration.  Much as before, we still register our types with a name, type and so on.  &lt;br /&gt;
&lt;br /&gt;
But, what's interesting is that we now have the ability to do type injection through a Unity extension called the TypeInjectionElement.  This allows us to inject into the constructor and put in our parameters as need be.  But we could also replace that with &amp;lt;method&amp;gt; or &amp;lt;property&amp;gt; in order to do method injection and property setter injection respectively.  &lt;br /&gt;
Within the &amp;lt;param&amp;gt; element, we can specify our given injection element parameters.  This allows us to specify the name of our given parameter, the type, but also for the dependency check, we can specify the name and type to alias the other &amp;lt;type&amp;gt; elements that we wish to get a reference of.  We can also specify the values if we so desire of strings, integers and so on.  Below is a simple example of using both dependency references and values.&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;constructor&amp;gt;\par ??\tab &amp;lt;param \cf3 name\cf1 ="\cf4 logger\cf1 " \cf3 parameterType\cf1 ="\cf4 ILogger\cf1 "&amp;gt;\par ??\tab \tab &amp;lt;dependency \cf3 name\cf1 ="\cf4 debugLogger\cf1 "/&amp;gt;\par ??\tab &amp;lt;/param&amp;gt;\par ??\tab &amp;lt;param \cf3 name\cf1 ="\cf4 dbName\cf1 " \cf3 parameterType\cf1 ="\cf4 string\cf1 "&amp;gt;\par ??\tab \tab &amp;lt;value \cf3 value\cf1 ="\cf4 AdventureWorks\cf1 " /&amp;gt;\par ??\tab &amp;lt;/param&amp;gt;\par ??&amp;lt;/constructor&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;constructor&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;param &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;parameterType&lt;/span&gt;="&lt;span style="color: lime;"&gt;ILogger&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &amp;lt;dependency &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;debugLogger&lt;/span&gt;"/&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/param&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;param &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;dbName&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;parameterType&lt;/span&gt;="&lt;span style="color: lime;"&gt;string&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &amp;lt;value &lt;span style="color: rgb(255, 128, 0);"&gt;value&lt;/span&gt;="&lt;span style="color: lime;"&gt;AdventureWorks&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;    &amp;lt;/param&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&amp;lt;/constructor&amp;gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
I find the best way to learn about these features usually isn't through documentation, although it's a nice thing to do, but instead the tests.  I look for the functionality that I'm interested in and go deep.  A project this size without good unit tests == &lt;span style="font-weight: bold;"&gt;FAIL &lt;/span&gt;in my opinion.  Anyhow, this is better looking than it used to be and much more intuitive.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Interception Revisited&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As Chris Tavares, the developer of Unity noted on my blog before was the fact that he could easily put in the interceptors from the ObjectBuilder2 since ObjectBuilder2 is modular and Unity is built upon it.  It shouldn't have been news, because I've been working on that myself to get lightweight interception to work on it.  Maybe when I get it fully implemented I'll share it.  But in the mean time, it's just a spike.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I think this approach has helped in the XML configuration goo that had been a bit confusing.  I didn't want to clutter my domain models and processing code with excess attributes stating intent, and would rather keep it clean.  This makes a step in that direction.  In the next installation of looking at IoC will revolve around Spring.NET and AOP in the Enterprise, so stay tuned...  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/27/120808.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/27/120808.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120808"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120808" 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/120808.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/27/120808.aspx</guid>
            <pubDate>Fri, 28 Mar 2008 00:52:01 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120808.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/27/120808.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120808.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120808.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>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 Containers, Unity and ObjectBuilder2 - The Saga Continues</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/03/04/120185.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/07/120336.aspx"&gt;IoC Container, Unity and Breaking Changes Galore&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
I just wanted to revisit the whole &lt;a href="http://codeplex.com/unity"&gt;Unity Application Block&lt;/a&gt; just once more to look at a few more things including handling parameters, instances and so on.  If you hadn't seen, there was another source drop of Unity as of 2/26, so if you haven't picked it up, feel free to do so &lt;a mce_href="http://www.codeplex.com/unity/Release/ProjectReleases.aspx" href="http://www.codeplex.com/unity/Release/ProjectReleases.aspx"&gt;here&lt;/a&gt;.  &lt;br /&gt;
&lt;br /&gt;
So, we're going to continue our look at DI and IoC containers as they pertain to different needs.  I'm not going to be a gloryhound about any particular IoC container, instead, just lay out how each one does its job and you decide whether you want to use it or not.  And that's the main point I want to emphasize here that each tool has its purpose and its needs that it solves and it's up to you do decide whether it meets your needs and programming style.&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;
Anyhow, I covered the Unity Application Block in a few other posts lately as it relates to other Inversion of Control (IoC) containers.  I covered the basics with the Unity Application Block, &lt;a href="http://structuremap.sourceforge.net/"&gt;StructureMap &lt;/a&gt;and &lt;a href="http://www.castleproject.org/container/index.html"&gt;Castle Windsor&lt;/a&gt;.  Check them out before we go any further today:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/26/120002.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;/ul&gt;
Now that we're caught up to where we have been, let's dive into the other subjects in the same area of concern.  Unity has an interesting way of dealing with several issues that I want to cover in respect to other IoC containers.  And they are:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Managing Instances and Parameters&lt;/li&gt;
    &lt;li&gt;Method Call Injection&lt;/li&gt;
    &lt;li&gt;Unity Application Block versus ObjectBuilder2&lt;/li&gt;
&lt;/ul&gt;
&lt;span style="font-weight: bold;"&gt;Managing Instances or Parameters?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The previous two times, we talked about constructor injection and setter injection, but not really about managing simple types and mapping them to our constructors.  It's usually a simple thing, but yet, we have three different ways of attacking the very same problem.  That's the very point of these blog posts to point that out and it's once again echoed here.&lt;br /&gt;
&lt;br /&gt;
To set up this scenario, we have a simple SmtpEmailService which is used to send emails to users in our system.  It's a pretty naive sample, yet will illustrate some simple constructor injection with both simple and complex types.  We're going to inject a default from address and a logger into our service and go from there.&lt;br /&gt;
&lt;br /&gt;
We'll start with our Unity sample of how we are going to map those simple and complex types to the constructor.  Let's start off with the basic logger interface and implementation.  I'll only post this part once as it will apply the same to each of the samples.&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 once again, we have our concrete implementation with the console logger.&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 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  \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, let's tie it together with the point of today's post, the SmtpEmailService.  We will have two parameters in this scenario, the default email address, and the logger used for logging.&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 SmtpEmailService\cf3  : \cf5 IEmailService\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf1 string\cf3  defaultFromAddress;\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf5 ILogger\cf3  logger;\par ??\par ??        \cf1 public\cf3  SmtpEmailService([\cf4 Dependency\cf3 (\cf6 "defaultFromAddress"\cf3 )] \cf1 string\cf3  defaultFromAddress, \cf5 ILogger\cf3  logger)\par ??        \{\par ??            \cf1 this\cf3 .defaultFromAddress = defaultFromAddress;\par ??            \cf1 this\cf3 .logger = logger;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SendEmail(\cf1 string\cf3  to, \cf1 string\cf3  subject, \cf1 string\cf3  body)\par ??        \{\par ??            \cf6 // Send email\par ??\cf3             logger.Log(\cf1 string\cf3 .Format(\cf6 "Sending email from \{0\} to \{1\} with the subject \{2\} and body \{3\}"\cf3 , defaultFromAddress, to, subject, body));\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;SmtpEmailService&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IEmailService&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(255, 128, 0);"&gt;string&lt;/span&gt; defaultFromAddress;&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;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;public&lt;/span&gt; SmtpEmailService([&lt;span style="color: yellow;"&gt;Dependency&lt;/span&gt;(&lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;/span&gt;)] &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; defaultFromAddress, &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;this&lt;/span&gt;.defaultFromAddress = defaultFromAddress;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;this&lt;/span&gt;.logger = logger;&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; SendEmail(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; to, &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; subject, &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; body)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: lime;"&gt;// Send email&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger.Log(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: lime;"&gt;"Sending email from {0} to {1} with the subject {2} and body {3}"&lt;/span&gt;, defaultFromAddress, to, subject, body));&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'm using the DependencyAttribute to decorate the parameter defaultFromAddress.  This correlates to the key specified in the config file or when you register an instance, and I'll show you that later.   &lt;br /&gt;
Let's take a look at the program.cs to use the XML config file to wire up our instances.&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 ??\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 SmtpEmailService\cf3  service = container.Get&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;();\par ??            service.SendEmail(\cf6 "me@example.com"\cf3 , \cf6 "Test email"\cf3 , \cf6 "This is a test email"\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; System.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;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;SmtpEmailService&lt;/span&gt; service = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            service.SendEmail(&lt;span style="color: lime;"&gt;"me@example.com"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"Test email"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"This is a test email"&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;
The above code is pretty standard as we've used before, so real surprises here.  So, let's take a look at the XML configuration necessary to make this work:&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 ??\tab &amp;lt;configSections&amp;gt;\par ??\tab \tab &amp;lt;section \cf3 name\cf1 ="\cf4 unity\cf1 "\par ??\tab \tab \tab \tab \cf3 type\cf1 ="\cf4 Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,\par ??                  Microsoft.Practices.Unity.Configuration\cf1 " /&amp;gt;\par ??\tab &amp;lt;/configSections&amp;gt;\par ??\tab &amp;lt;unity&amp;gt;\par ??\tab \tab &amp;lt;containers&amp;gt;\par ??\tab \tab \tab &amp;lt;container&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;types&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;type \cf3 type\cf1 ="\cf4 UnitySamples.ILogger,UnitySamples\cf1 "\par ??\tab \tab \tab \tab \tab \tab   \cf3 mapTo\cf1 ="\cf4 UnitySamples.ConsoleLogger,UnitySamples\cf1 "\par ??\tab \tab \tab \tab \tab \tab   \cf3 lifetime\cf1 ="\cf4 Singleton\cf1 "/&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;/types&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;instances&amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;add \cf3 name\cf1 ="\cf4 defaultFromAddress\cf1 " \cf3 type\cf1 ="\cf4 System.String\cf1 " \cf3 value\cf1 ="\cf4 administrator@example.com\cf1 " /&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;/instances&amp;gt;\par ??\tab \tab \tab &amp;lt;/container&amp;gt;\par ??\tab \tab &amp;lt;/containers&amp;gt;\par ??\tab &amp;lt;/unity&amp;gt;\par ??&amp;lt;/configuration&amp;gt;\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;&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;instances&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                    &amp;lt;add &lt;span style="color: rgb(255, 128, 0);"&gt;name&lt;/span&gt;="&lt;span style="color: lime;"&gt;defaultFromAddress&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;type&lt;/span&gt;="&lt;span style="color: lime;"&gt;System.String&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;value&lt;/span&gt;="&lt;span style="color: lime;"&gt;administrator@example.com&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &amp;lt;/instances&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;
What I did is that I utilized the instances node and then add an instance called defaultFromAddress.  This node is only used to initialize simple types such as strings, DateTimes, System.Doubles, System.Int32 and so on.  Then I can set the value as well.  So, if I want to initialize complex types in the types node and the simple types in the instances node.&lt;br /&gt;
&lt;br /&gt;
But, we can also register things through the regular programmatic interfaces as well such as 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 ??            \cf5 IUnityContainer\cf3  container = \cf1 new\cf3  \cf4 UnityContainer\cf3 ();\par ??            container\par ??                .Register&amp;lt;\cf5 ILogger\cf3 , \cf4 ConsoleLogger\cf3 &amp;gt;()\par ??                .SetSingleton&amp;lt;\cf5 ILogger\cf3 &amp;gt;()\par ??                .RegisterInstance&amp;lt;\cf1 string\cf3 &amp;gt;(\cf6 "administrator@example.com"\cf3 , \cf6 "defaultFromAddress"\cf3 );\par ??\par ??\par ??            \cf6 //UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");\par ??\cf3             \cf6 //section.Containers.Default.GetConfigCommand().Configure(container);\par ??\cf3             \cf4 SmtpEmailService\cf3  service = container.Get&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;();\par ??            service.SendEmail(\cf6 "me@example.com"\cf3 , \cf6 "Test email"\cf3 , \cf6 "This is a test email"\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: 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;                .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;/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&gt;, &lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt; service = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            service.SendEmail(&lt;span style="color: lime;"&gt;"me@example.com"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"Test email"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"This is a test email"&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 note, I used the fluent interfaces approach to register the ConsoleLogger as well as the instance of type string which had my value and the key I wanted to use.  The first value I use is the value, and the second is the key I want to use to correlate to my DependencyAttribute.&lt;br /&gt;
&lt;br /&gt;
Now, let's look at the StructureMap instance using the same approach.  The only pieces I intend to show are just the pieces I changed.  So, let's take a look at the SmtpEmailService once again.&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  StructureMapSamples\par ??\{\par ??    \cf1 public\cf3  \cf1 class\cf3  \cf4 SmtpEmailService\cf3  : \cf5 IEmailService\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf1 string\cf3  defaultFromAddress;\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf5 ILogger\cf3  logger;\par ??\par ??        \cf1 public\cf3  SmtpEmailService(\cf1 string\cf3  defaultFromAddress, \cf5 ILogger\cf3  logger)\par ??        \{\par ??            \cf1 this\cf3 .defaultFromAddress = defaultFromAddress;\par ??            \cf1 this\cf3 .logger = logger;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SendEmail(\cf1 string\cf3  to, \cf1 string\cf3  subject, \cf1 string\cf3  body)\par ??        \{\par ??            \cf6 // Send email\par ??\cf3             logger.Log(\cf1 string\cf3 .Format(\cf6 "Sending email from \{0\} to \{1\} with the subject \{2\} and body \{3\}"\cf3 , defaultFromAddress, to, subject, body));\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; 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;public&lt;/span&gt; &lt;span style="color: rgb(255, 128, 0);"&gt;class&lt;/span&gt; &lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IEmailService&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(255, 128, 0);"&gt;string&lt;/span&gt; defaultFromAddress;&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;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;public&lt;/span&gt; SmtpEmailService(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; defaultFromAddress, &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;this&lt;/span&gt;.defaultFromAddress = defaultFromAddress;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;this&lt;/span&gt;.logger = logger;&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; SendEmail(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; to, &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; subject, &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; body)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: lime;"&gt;// Send email&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger.Log(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: lime;"&gt;"Sending email from {0} to {1} with the subject {2} and body {3}"&lt;/span&gt;, defaultFromAddress, to, subject, body));&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 from above, I had no need for the dependency attribute or anything like that.  I haven't bothered to put the PluginAttributes or anything like that either as I want to do XML config way.  So, let's next look at the program.cs which does the simple email wireup.  &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;\red0\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 SmtpEmailService\cf3  service = \cf4 ObjectFactory\cf3 .GetInstance&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;();\par ??            service.SendEmail(\cf5 "me@example.com"\cf3 , \cf5 "Test email"\cf3 , \cf5 "This is a test email"\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; 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;SmtpEmailService&lt;/span&gt; service = &lt;span style="color: yellow;"&gt;ObjectFactory&lt;/span&gt;.GetInstance&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            service.SendEmail(&lt;span style="color: lime;"&gt;"me@example.com"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"Test email"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"This is a test email"&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;
And then we wire things up with our StructureMap.config file.  Note that we set up things through an Instance node and then set the constructor injection parameters through property nodes.&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 ??\tab &amp;lt;Aseembly \cf3 Name\cf1 ="\cf4 StructureMapSamples\cf1 "/&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 " \cf3 Scope\cf1 ="\cf4 Singleton\cf1 "&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.SmtpEmailService\cf1 " \cf3 Assembly\cf1 ="\cf4 StructureMapSamples\cf1 " \cf3 DefaultKey\cf1 ="\cf4 EmailService\cf1 "&amp;gt;\par ??\tab   &amp;lt;Plugin \cf3 Assembly\cf1 ="\cf4 StructureMapSamples\cf1 " \cf3 Type\cf1 ="\cf4 StructureMapSamples.SmtpEmailService\cf1 " \cf3 ConcreteKey\cf1 ="\cf4 SmtpEmailService\cf1 " /&amp;gt;\par ??\tab   &amp;lt;Instance \cf3 Key\cf1 ="\cf4 EmailService\cf1 " \cf3 Type\cf1 ="\cf4 SmtpEmailService\cf1 "&amp;gt;\par ??\tab \tab   &amp;lt;Property \cf3 Name\cf1 ="\cf4 defaultFromAddress\cf1 " \cf3 Value\cf1 ="\cf4 administrator@example.com\cf1 " /&amp;gt;\par ??\tab \tab   &amp;lt;Property \cf3 Name\cf1 ="\cf4 logger\cf1 " \cf3 Key\cf1 ="\cf4 Console\cf1 " /&amp;gt;\par ??\tab   &amp;lt;/Instance&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;Aseembly &lt;span style="color: rgb(255, 128, 0);"&gt;Name&lt;/span&gt;="&lt;span style="color: lime;"&gt;StructureMapSamples&lt;/span&gt;"/&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;" &lt;span style="color: rgb(255, 128, 0);"&gt;Scope&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;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.SmtpEmailService&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;EmailService&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.SmtpEmailService&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;ConcreteKey&lt;/span&gt;="&lt;span style="color: lime;"&gt;SmtpEmailService&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;      &amp;lt;Instance &lt;span style="color: rgb(255, 128, 0);"&gt;Key&lt;/span&gt;="&lt;span style="color: lime;"&gt;EmailService&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Type&lt;/span&gt;="&lt;span style="color: lime;"&gt;SmtpEmailService&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;          &amp;lt;Property &lt;span style="color: rgb(255, 128, 0);"&gt;Name&lt;/span&gt;="&lt;span style="color: lime;"&gt;defaultFromAddress&lt;/span&gt;" &lt;span style="color: rgb(255, 128, 0);"&gt;Value&lt;/span&gt;="&lt;span style="color: lime;"&gt;administrator@example.com&lt;/span&gt;" /&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;          &amp;lt;Property &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;/Instance&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;
I tidied up the XML configuration a bit after taking Jeremy Miller's advice and trying to collapse it down as much as possible.  I'm sure I still don't have it to the smallest amount possible, but at least it's legible.  Now, let's go ahead and use the DSL for configuration instead of the simple program.cs we have above.&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  StructureMap;\par ??\cf1 using\cf3  StructureMap.Configuration.DSL;\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 StructureMapConfiguration\cf3 .UseDefaultStructureMapConfigFile = \cf1 false\cf3 ;\par ??            \cf4 StructureMapConfiguration\cf3 .BuildInstancesOf&amp;lt;\cf5 ILogger\cf3 &amp;gt;()\par ??                .TheDefaultIsConcreteType&amp;lt;\cf4 ConsoleLogger\cf3 &amp;gt;().AsSingletons();\par ??            \cf4 StructureMapConfiguration\cf3 .BuildInstancesOf&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;().TheDefaultIs(\par ??                \cf4 Registry\cf3 .Instance&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;().UsingConcreteType&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;()\par ??                    .WithProperty(\cf6 "defaultFromAddress"\cf3 ).EqualTo(\cf6 "administrator@example.com"\cf3 ));\par ??            \cf4 SmtpEmailService\cf3  service = \cf4 ObjectFactory\cf3 .GetInstance&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;();\par ??            service.SendEmail(\cf6 "me@example.com"\cf3 , \cf6 "Test email"\cf3 , \cf6 "This is a test email"\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; StructureMap;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; StructureMap.Configuration.DSL;&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;StructureMapConfiguration&lt;/span&gt;.UseDefaultStructureMapConfigFile = &lt;span style="color: rgb(255, 128, 0);"&gt;false&lt;/span&gt;;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;StructureMapConfiguration&lt;/span&gt;.BuildInstancesOf&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;                .TheDefaultIsConcreteType&amp;lt;&lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;&amp;gt;().AsSingletons();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;StructureMapConfiguration&lt;/span&gt;.BuildInstancesOf&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;().TheDefaultIs(&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &lt;span style="color: yellow;"&gt;Registry&lt;/span&gt;.Instance&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;().UsingConcreteType&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;()&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                    .WithProperty(&lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;/span&gt;).EqualTo(&lt;span style="color: lime;"&gt;"administrator@example.com"&lt;/span&gt;));&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt; service = &lt;span style="color: yellow;"&gt;ObjectFactory&lt;/span&gt;.GetInstance&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            service.SendEmail(&lt;span style="color: lime;"&gt;"me@example.com"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"Test email"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"This is a test email"&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 can see from above, it's a pretty simple thing to use the more fluent interfaces here as well to register what we're interested in.  We're making sure it doesn't use the default StructureMap.config file and then build up an instance of an ILogger as a singleton, and then use the injection on the SmtpService to set the defaultFromAddress.  The ILogger it should automatically figure out itself.&lt;br /&gt;
&lt;br /&gt;
Now, let's finally move onto Castle Windsor.  I must admit, I'm most familiar with Castle Windsor, but I'm learning something new about each of these every day, which is a good thing.  So, the only classes I really need to show is the program.cs and the configuration file to show what has changed.  So, let's start with the program.cs file:&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;\red0\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 SmtpEmailService\cf3  service = container.Resolve&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;();\par ??            service.SendEmail(\cf5 "me@example.com"\cf3 , \cf5 "Test email"\cf3 , \cf5 "This is a test email"\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.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;SmtpEmailService&lt;/span&gt; service = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            service.SendEmail(&lt;span style="color: lime;"&gt;"me@example.com"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"Test email"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"This is a test email"&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;
This is a pretty simple example of using the XmlInterpreter which reads the XML configuration file to read what we want to set.  And then our XML configuration file should look something 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 ??\tab &amp;lt;configSections&amp;gt;\par ??\tab \tab &amp;lt;section \cf3 name\cf1 ="\cf4 castle\cf1 "\par ??\tab \tab \tab \cf3 type\cf1 ="\cf4 Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor\cf1 " /&amp;gt;\par ??\tab &amp;lt;/configSections&amp;gt;\par ??\tab &amp;lt;castle&amp;gt;\par ??\tab \tab &amp;lt;components&amp;gt;\par ??\tab \tab \tab &amp;lt;component \cf3 id\cf1 ="\cf4 emailservice.smtp\cf1 "\par ??\tab \tab \tab \tab \cf3 type\cf1 ="\cf4 CastleSamples.SmtpEmailService, CastleSamples\cf1 "&amp;gt;\par ??\tab \tab \tab &amp;lt;parameters&amp;gt;\par ??\tab \tab \tab \tab &amp;lt;defaultFromAddress&amp;gt;administrator@example.com&amp;lt;/defaultFromAddress&amp;gt;\par ??\tab \tab \tab &amp;lt;/parameters&amp;gt;\par ??\tab \tab &amp;lt;/component&amp;gt;\par ??\tab \tab &amp;lt;component \cf3 id\cf1 ="\cf4 logger.console\cf1 "\par ??\tab \tab \tab \tab \tab    \cf3 service\cf1 ="\cf4 CastleSamples.ILogger, CastleSamples\cf1 "\par ??\tab \tab \tab \tab \tab    \cf3 type\cf1 ="\cf4 CastleSamples.ConsoleLogger, CastleSamples\cf1 "\par ??\tab \tab \tab \tab \tab    \cf3 lifestyle\cf1 ="\cf4 singleton\cf1 " /&amp;gt;\par ??\tab \tab &amp;lt;/components&amp;gt;\par ??\tab &amp;lt;/castle&amp;gt;\par ??&amp;lt;/configuration&amp;gt;\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;&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;emailservice.smtp&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;CastleSamples.SmtpEmailService, CastleSamples&lt;/span&gt;"&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;parameters&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                &amp;lt;defaultFromAddress&amp;gt;administrator@example.com&amp;lt;/defaultFromAddress&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &amp;lt;/parameters&amp;gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        &amp;lt;/component&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;/p&gt;
&lt;p style="margin: 0px;"&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;/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;CastleSamples.ConsoleLogger, CastleSamples&lt;/span&gt;"&lt;/p&gt;
&lt;p style="margin: 0px;"&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;
I could have also specified the logger as well as a parameter by noting it inside the parameters node such as this:&lt;br /&gt;
&amp;lt;logger&amp;gt;${logger.console}&amp;lt;/logger&amp;gt; to specify that it uses the ConsoleLogger, but it's not really necessary to do so.&lt;br /&gt;
&lt;br /&gt;
Instead, let's use the XML free way of configuration just to prove a point we can do it both ways:&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;\red0\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 using\cf3  System.Collections.Generic;\par ??\cf1 using\cf3  Castle.Core;\par ??\cf1 using\cf3  Castle.Windsor;\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 ();\par ??            container.AddComponentWithLifestyle(\cf5 "logger.console"\cf3 , \cf1 typeof\cf3  (\cf6 ILogger\cf3 ), \cf1 typeof\cf3  (\cf4 ConsoleLogger\cf3 ),\par ??                                                \cf6 LifestyleType\cf3 .Singleton);\par ??            \cf4 Dictionary\cf3 &amp;lt;\cf1 string\cf3 , \cf1 object\cf3 &amp;gt; properties = \cf1 new\cf3  \cf4 Dictionary\cf3 &amp;lt;\cf1 string\cf3 , \cf1 object\cf3 &amp;gt;();\par ??            properties.Add(\cf5 "defaultFromAddress"\cf3 , \cf5 "administrator@example.com"\cf3 );\par ??            container.AddComponent(\cf5 "emailservice.smtp"\cf3 , \cf1 typeof\cf3  (\cf4 SmtpEmailService\cf3 ));\par ??\par ??            \cf4 SmtpEmailService\cf3  service = container.Resolve&amp;lt;\cf4 SmtpEmailService\cf3 &amp;gt;(properties);\par ??            service.SendEmail(\cf5 "me@example.com"\cf3 , \cf5 "Test email"\cf3 , \cf5 "This is a test email"\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; System.Collections.Generic;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;using&lt;/span&gt; Castle.Core;&lt;/p&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;/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;/p&gt;
&lt;p style="margin: 0px;"&gt;            container.AddComponentWithLifestyle(&lt;span style="color: lime;"&gt;"logger.console"&lt;/span&gt;, &lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt; (&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;), &lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt; (&lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;),&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                                &lt;span style="color: rgb(43, 145, 175);"&gt;LifestyleType&lt;/span&gt;.Singleton);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: yellow;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(255, 128, 0);"&gt;object&lt;/span&gt;&amp;gt; properties = &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(255, 128, 0);"&gt;object&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            properties.Add(&lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"administrator@example.com"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            container.AddComponent(&lt;span style="color: lime;"&gt;"emailservice.smtp"&lt;/span&gt;, &lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt; (&lt;span style="color: yellow;"&gt;SmtpEmailService&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;SmtpEmailService&lt;/span&gt; service = container.Resolve&amp;lt;&lt;span style="color: yellow;"&gt;SmtpEmailService&lt;/span&gt;&amp;gt;(properties);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            service.SendEmail(&lt;span style="color: lime;"&gt;"me@example.com"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"Test email"&lt;/span&gt;, &lt;span style="color: lime;"&gt;"This is a test email"&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, as you can see, it's pretty simple to set the parameters on our SmtpEmailService through the use of a Dictionary&amp;lt;TKey, TValue&amp;gt; generic collection.  The rest is just plain simple.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Method Call Injection&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The Unity Application Block introduces another concept called method call injection.  Yes, that's right, instead of using constructor injection or setter injection, you can use method call injection.  The basic premise is that you can inject any method as you would for a constructor or setter.&lt;br /&gt;
&lt;br /&gt;
When would you use this though?  If you read the documentation, it lays out the explanation as follows:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;You want to instantiate dependent objects automatically when your instantiate the parent object&lt;/li&gt;
    &lt;li&gt;You want a simple approach that makes it easy to see in the code what the dependencies are for each class &lt;/li&gt;
    &lt;li&gt;The parent object requires a large number of constructors that forward to each other, making debugging and maintenance difficult &lt;/li&gt;
    &lt;li&gt;The parent object constructors require a large number of parameters, especially if they are of similar types and the only way to identify them is by position &lt;/li&gt;
    &lt;li&gt;You want to hide the dependent objects by not exposing them as properties &lt;/li&gt;
    &lt;li&gt;You want to control which objects are injected by editing the code of the dependent object instead of the parent object or application &lt;br /&gt;
    &lt;/li&gt;
&lt;/ul&gt;
By default unless any of this matches your criteria, you should just go ahead and use constructor injection.  But, let's walk through a small sample of using method injection:&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 SmtpEmailService\cf3  : \cf5 IEmailService\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 string\cf3  defaultFromAddress;\par ??        \cf1 private\cf3  \cf5 ILogger\cf3  logger;\par ??\par ??        [\cf4 InjectionMethod\cf3 ]\par ??        \cf1 public\cf3  \cf1 void\cf3  Initialize([\cf4 Dependency\cf3 (\cf6 "defaultFromAddress"\cf3 )] \cf1 string\cf3  defaultFromAddress, \cf5 ILogger\cf3  logger)\par ??        \{\par ??            \cf1 this\cf3 .defaultFromAddress = defaultFromAddress;\par ??            \cf1 this\cf3 .logger = logger;\par ??        \}\par ??\par ??        \cf1 public\cf3  \cf1 void\cf3  SendEmail(\cf1 string\cf3  to, \cf1 string\cf3  subject, \cf1 string\cf3  body)\par ??        \{\par ??            \cf6 // Send email\par ??\cf3             logger.Log(\cf1 string\cf3 .Format(\cf6 "Sending email from \{0\} to \{1\} with the subject \{2\} and body \{3\}"\cf3 , defaultFromAddress, to, subject, body));\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;SmtpEmailService&lt;/span&gt; : &lt;span style="color: rgb(43, 145, 175);"&gt;IEmailService&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;string&lt;/span&gt; defaultFromAddress;&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;/p&gt;
&lt;p style="margin: 0px;"&gt; &lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        [&lt;span style="color: yellow;"&gt;InjectionMethod&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; Initialize([&lt;span style="color: yellow;"&gt;Dependency&lt;/span&gt;(&lt;span style="color: lime;"&gt;"defaultFromAddress"&lt;/span&gt;)] &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; defaultFromAddress, &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;this&lt;/span&gt;.defaultFromAddress = defaultFromAddress;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: rgb(255, 128, 0);"&gt;this&lt;/span&gt;.logger = logger;&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; SendEmail(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; to, &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; subject, &lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt; body)&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;        {&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            &lt;span style="color: lime;"&gt;// Send email&lt;/span&gt;&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            logger.Log(&lt;span style="color: rgb(255, 128, 0);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: lime;"&gt;"Sending email from {0} to {1} with the subject {2} and body {3}"&lt;/span&gt;, defaultFromAddress, to, subject, body));&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;
The rest of our program shouldn't have to change with this scenario.  But, as you will note from above, we decorated our Initialize method with an InjectionMethodAttribute which makes it realize that instead of constructor injection, use this instead.  And it works like a charm.  I haven't run into a scenario yet where I would find it useful, but I find it interesting.  If anyone does have a scenario that they've run into, please let me know.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt; Unity == ObjectBuilder2?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you may have noticed, if you had downloaded the Unity Application Block, you'll notice that it is built upon ObjectBuilder2, but you may also notice that it hides a lot of functionality that it provides.  When you are marking your classes with DependencyAttribute and other things, you will notice that there are two of them, one in Unity and one in ObjectBuilder2, so this got me curious on what else I was missing out on.&lt;br /&gt;
&lt;br /&gt;
If you've played around with Enterprise Library in the past, you have probably dealt with ObjectBuilder.  It was not the most delightful piece of code I've ever had to deal with and not very intuitive.  &lt;a href="http://bradwilson.typepad.com/"&gt;Brad Wilson&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/scottdensmore/"&gt;Scott Densmore&lt;/a&gt; took it upon themselves to rewrite this into a much more usable piece of code.  You can download the original and unencumbered ObjectBuilder2 from CodePlex &lt;a href="http://www.codeplex.com/ObjectBuilder/SourceControl/DownloadSourceCode.aspx?changeSetId=29957"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Take a look at the CodePlex DependencyInjection project and its associated tests in Tests.CodePlex.DependencyInjection for a good idea on how well Brad and Scott did with their DI framework.  The best way to learn about any framework is to read the tests or specs (BDD style of course).  Let's look at two ways of doing code interception using the DI framework with using code and using attributes.&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 ??            \}\par ??\par ??            [\cf3 Fact\cf1 ]\par ??            \cf4 public\cf1  \cf4 void\cf1  InterceptViaCode()\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 SpyInterface\cf1 &amp;gt;();\par ??                container.InterceptInterface&amp;lt;\cf3 SpyInterface\cf1 &amp;gt;(\cf4 typeof\cf1 (\cf5 ISpy\cf1 ).GetMethod(\cf6 "InterceptedMethod"\cf1 ),\par ??                                                           \cf4 new\cf1  \cf3 RecordingHandler\cf1 ());\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;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; InterceptViaCode()&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;SpyInterface&lt;/span&gt;&amp;gt;();&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                container.InterceptInterface&amp;lt;&lt;span style="color: yellow;"&gt;SpyInterface&lt;/span&gt;&amp;gt;(&lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;ISpy&lt;/span&gt;).GetMethod(&lt;span style="color: lime;"&gt;"InterceptedMethod"&lt;/span&gt;),&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;                                                           &lt;span style="color: rgb(255, 128, 0);"&gt;new&lt;/span&gt; &lt;span style="color: yellow;"&gt;RecordingHandler&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;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;
Ok, so you may note that we registered this with an ISpy interface.  Then we have two implementations, one with code and one using attributes.  Let's now inspect that 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 ??            \}\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;SpyInterface&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;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: 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;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;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;p style="margin: 0px;"&gt;        }&lt;/p&gt;
&lt;/div&gt;
&lt;br /&gt;
As you may note, we have two methods that we're interested in, the InterceptedMethod and the ThrowsException method.  Then we can test through a Recorder that in fact the code was hit.  &lt;a href="http://www.codeplex.com/xunit"&gt;xUnit.net&lt;/a&gt; is used quite frequently throughout the code as it is a project also by Brad and &lt;a href="http://blogs.msdn.com/jamesnewkirk/"&gt;Jim Newkirk&lt;/a&gt;.  Overall, I'm very impressed with this code and I wish it had made more of an impact.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.tavaresstudios.com/blog"&gt; Chris Tavares&lt;/a&gt; and others from the Unity team have taken it upon themselves to redo a lot of the guts of ObjectBuilder2 as they continue to extend Unity.  For AOP, the plan is to include the Policy Injection Block into the solution, whereas ObjectBuilder2 already had this piece of functionality and does it quite well.  Some of it seems to be right now a little less featured than ObjectBuilder2 at this point, but that can change.  I have hopes for Unity, but ObjectBuilder2 did a lot of these things that it claims to do, just a little bit better.&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;
Here wraps up another installment of looking at IoC containers and the various frameworks associated with it.  I hope that it whets your appetite to not only understand these containers, but see how they work deep down and see which matches your programming style.  Get to know your tools just a little bit better and find out what good quality code can be.  I hope you can take this to heart and see what works for you. &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/03/04/120185.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/04/120185.aspx" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120185"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120185" 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/120185.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/03/04/120185.aspx</guid>
            <pubDate>Tue, 04 Mar 2008 08:15:34 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/120185.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/03/04/120185.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/120185.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/120185.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>IoC and the Unity Application Block - Going Deeper</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/02/22/119911.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/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;br /&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;
&lt;br /&gt;
I thought after my &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/21/119880.aspx"&gt;recent F# post,&lt;/a&gt; I'd get back to the Unity post that was halfway done before the firestorm began...&lt;br /&gt;
&lt;br /&gt;
In a &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/18/119744.aspx"&gt;previous post&lt;/a&gt;, I showed how easy it was to create a basic application using the Unity Application Block. I'm always finding new ways to solve my problems and new tools to do it.  Since Inversion of Control (IoC) containers are near and dear to my heart, I thought I'd investigate to see whether it meets my needs or not.  It's something you need to determine on your own, whether it works for you.  Some like &lt;a href="http://www.springframework.net/"&gt;Spring.NET&lt;/a&gt;, others &lt;a href="http://structuremap.sourceforge.net/"&gt;StructureMap&lt;/a&gt;, &lt;a href="http://castleproject.org/"&gt;Castle Windsor&lt;/a&gt; and so on.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Purse Fight???&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now, there has been some rather heated discussion around the Unity Application Block on the &lt;a href="http://tech.groups.yahoo.com/group/altdotnet/"&gt;altdotnet &lt;/a&gt;mailing list.  The discussion even got heated enough for the &lt;a href="http://altnetpursefight.blogspot.com/"&gt;ALT.NET Pursefight blog&lt;/a&gt; to come back into action after a long hibernation with a post called &lt;a href="http://altnetpursefight.blogspot.com/2008/02/dear-idiots.html"&gt;"Dear Idiots"&lt;/a&gt;...&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Compare/Contrast with Windsor&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Anyhow, today I will focus on a little compare/contrast with Castle Windsor just to show the different styles used.  I'm not going to say one is better than the other, because quite frankly, that's up to you to decide...  I want to thank &lt;a href="http://diditwith.net/"&gt;Dustin Campbell&lt;/a&gt; for his help in getting a better code formatter via this post &lt;a href="http://diditwith.net/2007/08/16/CopySourceAsHtmlInVisualStudio2008.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
So, let's just take a sample from before and have our ILogger and create a singleton first using the Unity Container.  So, we will go ahead and use the ILogger interface, and create a concrete implementation of that called ConsoleLogger, inject it into the constructor and then call the Log method from within the CustomerTasks class.  Pretty simple scenario especially when dealing with cross cutting concerns.  So, the code to do this is below.&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;
Now that we have a simple, undecorated interface, let's actually implement it in code for a simple console logger.  Not practical for real use, but shows a point.&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;\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; ConsoleLogger()&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(&lt;span style="color: lime;"&gt;"Hello from constructor"&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; 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 we have that, let's create a class that takes an ILogger through constructor injection.&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 CustomerTasks\par ??\cf3     \{\par ??        \cf1 private\cf3  \cf1 readonly\cf3  \cf5 ILogger\cf3  logger;\par ??\par ??        \cf1 public\cf3  CustomerTasks(\cf5 ILogger\cf3  logger)\par ??        \{\par ??            \cf1 this\cf3 .logger = logger;\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;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(255, 128, 0);"&gt;readonly&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;public&lt;/span&gt; CustomerTasks(&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;this&lt;/span&gt;.logger = 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;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;
Ok, time to actually start up the UnityContainer by registering everything through code.  It's a pretty simple operation.  We want the ILogger instance to be a singleton instance.  This happens during the registration process by calling the SetSingleton&amp;lt;T&amp;gt;() method off the container itself.  Note the nice fluent interfaces for doing this component 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 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  container = \cf1 new\cf3  \cf4 UnityContainer\cf3 ();\par ??            container.Register&amp;lt;\cf5 ILogger\cf3 , \cf4 ConsoleLogger\cf3 &amp;gt;().SetSingleton&amp;lt;\cf4 ConsoleLogger\cf3 &amp;gt;();\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; 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; 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.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;(new &lt;span style="color: yellow;"&gt;ContainerControlledLifetimeManager&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;
So, as you can see, no real config file was really necessary for me to do any of this.  It was a simple registration process of creating a UnityContainer.  But, that's not ideal, so let's set it as a singleton using the config file instead:&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.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;
You'll notice that the configuration is still kind of awkward for having to get the configuration section this way and I'm hoping for a cleaner registration soon enough.  And the configuration file would look like this for the registration.  Note that I'm setting the lifetime to Singleton.  For those familiar with Castle Windsor, it should look pretty familiar.&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;
So, now that we have this, let's run it and sure enough, the results are:&lt;br /&gt;
&lt;table width="100%" cellspacing="0" cellpadding="0" border="0" align="" style="color: rgb(255, 255, 255); background-color: black;" summary=""&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;Hello from constructor&lt;br /&gt;
            Saved customer&lt;br /&gt;
            Saved customer&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
So, we notice that the constructor was called only once, which was our point all along.  Now, let's mosey along and do the same with Castle Windsor.  The only thing I want to change is the Program.cs and sure enough I can do that pretty easily and just change the namespaces.  For brevity's sake, I won't repaste the code with just the namespace change, so let's actually just show the Program.cs below.  First, I'll try using the component registration through the code itself.&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;\red0\green255\blue0;\red43\green145\blue175;}??\fs16 \cf1\cb2\highlight2 using\cf3  Castle.Core;\par ??\cf1 using\cf3  Castle.Windsor;\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 ();\par ??            container.AddComponentWithLifestyle(\cf5 "logger.console"\cf3 , \cf1 typeof\cf3 (\cf6 ILogger\cf3 ), \cf1 typeof\cf3 (\cf4 ConsoleLogger\cf3 ), \cf6 LifestyleType\cf3 .Singleton);\par ??            container.AddComponent(\cf5 "customertasks"\cf3 , \cf1 typeof\cf3 (\cf4 CustomerTasks\cf3 ));\par ??\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.Core;&lt;/p&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;/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;/p&gt;
&lt;p style="margin: 0px;"&gt;            container.AddComponentWithLifestyle(&lt;span style="color: lime;"&gt;"logger.console"&lt;/span&gt;, &lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;ILogger&lt;/span&gt;), &lt;span style="color: rgb(255, 128, 0);"&gt;typeof&lt;/span&gt;(&lt;span style="color: yellow;"&gt;ConsoleLogger&lt;/span&gt;), &lt;span style="color: rgb(43, 145, 175);"&gt;LifestyleType&lt;/span&gt;.Singleton);&lt;/p&gt;
&lt;p style="margin: 0px;"&gt;            container.AddComponent(&lt;span style="color: lime;"&gt;"customertasks"&lt;/span&gt;, &lt;span style="color: rgb(255, 128, 0);"&gt;typeof&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: 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;
Well, once again, it's nice to show we can register through the code itself, but not super useful.  Instead, things like that should get moved over to the config file instead.  Let's redo the code to reflect that:&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 ??\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;/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;
Ok, so our program looks much simpler now, so, let's move the stuff into the app.config and it should look 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 ??\tab &amp;lt;configSections&amp;gt;\par ??\tab \tab &amp;lt;section \cf3 name\cf1 ="\cf4 castle\cf1 "\par ??\tab \tab \tab \cf3 type\cf1 ="\cf4 Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor\cf1 " /&amp;gt;\par ??\tab &amp;lt;/configSections&amp;gt;\par ??\tab &amp;lt;castle&amp;gt;\par ??\tab \tab &amp;lt;components&amp;gt;\par ??\tab \tab \tab &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 ??\tab \tab \tab &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 ??\tab \tab &amp;lt;/components&amp;gt;\par ??\tab &amp;lt;/castle&amp;gt;\par ??&amp;lt;/configuration&amp;gt;\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;&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;
And of course we run this and get the same result as we expected as before.  Now, what's cool is that none of my interfaces, nor implementations had any knowledge of my container, and so I can switch it out any time with no real harm to my components.  That's what I like.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Container Behavior&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Another interesting thing to note is how some containers handle ambiguous references.  &lt;a href="http://ayende.com/Blog/Default.aspx"&gt;Ayende &lt;/a&gt;recently posted on the altdotnet list about how Unity versus Castle Windsor resolves.  &lt;a href="http://codebetter.com/blogs/jeremy.miller/default.aspx"&gt;Jeremy Miller&lt;/a&gt; also chimed in as well with this.&lt;br /&gt;
&lt;br /&gt;
With this particular pseudocode, Castle Windsor can resolve this, while the other containers will fail due to an ambiguous reference.  &lt;br /&gt;
&lt;br /&gt;
container.Register&amp;lt;IDisposable, SqlConnection&amp;gt;("SQL")&lt;br /&gt;
   .Register&amp;lt;IDisposable, OracleConnection&amp;gt;("ORA");&lt;br /&gt;
&lt;br /&gt;
container.Get&amp;lt;IDisposable&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;AOP in Unity???&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In a previous post, I covered how you can do runtime weaving in Castle Windsor by implementing the IInterceptor interface and registering it through the config file.  So, does the Unity Application Block support something like this?  The answer is yes, but it's not out of the box.  Instead, you can build a UnityContainerExtension that supports the &lt;a href="http://bloggingabout.net/blogs/mveken/archive/2008/02/18/adding-a-policy-injection-extension-to-unity.aspx"&gt;Policy Injection Application Block (PIAB)&lt;/a&gt;.  &lt;a href="http://bloggingabout.net/blogs/mveken/"&gt;Martijn Veken&lt;/a&gt; has built an extension to use the PIAB and you can read more about it &lt;a href="http://bloggingabout.net/blogs/mveken/archive/2008/02/18/adding-a-policy-injection-extension-to-unity.aspx"&gt;here&lt;/a&gt;.  So, the AOP really isn't baked into Unity, but who knows, it may in the future, or it may just reside only in the PIAB.  Time will tell...&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, that's just the basics of a little Windsor and Unity bakeoff just to see some of the differences in philosophy.  I'd encourage everyone to take a look at most containers and find out which one really fits your need and programming style.  Competition and choice is a good thing.  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/22/119911.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/22/119911.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=119911"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119911" 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/119911.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/02/22/119911.aspx</guid>
            <pubDate>Sat, 23 Feb 2008 00:12:12 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/119911.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/02/22/119911.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/119911.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/119911.aspx</trackback:ping>
        </item>
        <item>
            <title>Adventures in F# - F# 101 Part 2</title>
            <link>http://geekswithblogs.net/Podwysocki/archive/2008/02/21/119880.aspx</link>
            <description>I know it's been a little bit too long since I began this series from when I continued, but plenty of distractions came up along the way.  I intend to go a little deeper today into what functional programming means and why you should care.  As always, check out my previous post on the matter &lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/02/11/119476.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Getting Sidetracked&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Last night at the &lt;a href="http://altnet.ent0.com/"&gt;DC ALT.NET&lt;/a&gt; meeting, &lt;a href="http://www.pluralsight.com/blogs/craig/"&gt;Craig Andera&lt;/a&gt; and I discussed Lisp, F# and functional programming as a whole.  His language of the year was Lisp and I thought that was an interesting choice of the language to learn, but when you think about it, most good things in programming lead back to SmallTalk and Lisp...  I had been hearing a bit about &lt;a href="http://www.codeplex.com/IronScheme"&gt;IronScheme&lt;/a&gt;, the &lt;a href="http://www.codeplex.com/IronLisp"&gt;IronLisp&lt;/a&gt; rewrite,  so of course I had to check it out.  Maybe this will be one of my future languages to learn, but I had enough exposure during my college years to last a little bit, so it's on the plan anyways.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Basic Introduction&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, just in case you missed the idea of functional programming and what it means, I have a few posts on where you should start here:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/18/118685.aspx"&gt;My Adventures in F#&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/Podwysocki/archive/2008/01/28/119022.aspx"&gt;Further Adventures in F#&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
But, if you really want the condensed version, Bart de Smet has a really nice introduction on functional programming in a series, although incomplete, which you can read here:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/01/16/foundations-of-functional-programming-part-0.aspx"&gt;Foundations of Functional Programming Part 0&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://community.bartdesmet.net/blogs/bart/archive/2008/01/27/foundations-of-functional-programming-part-1.aspx"&gt;Foundations of Functional Programming Part 1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
Now that I take it you have read that and caught up, let's continue onto today's part.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;The Joys of Currying&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Where we left off last time was just dealing with the basics of functions and the fact that they are treated as values much like any other "variable".  Now let's get into a popular topic among functional programming, a concept called &lt;a href="http://en.wikipedia.org/wiki/Currying"&gt;Currying&lt;/a&gt;.  The term was invented back in the earlier days of functional programming after the early logician &lt;a href="http://en.wikipedia.org/wiki/Haskell_Curry"&gt;Haskell Curry&lt;/a&gt;.  He's so good in fact that he got not only a functional programming style named after him, but a language named after him with &lt;a href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29"&gt;Haskell&lt;/a&gt;.  If you listen to the &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=310"&gt;DotNetRocks Episode 310&lt;/a&gt; with &lt;a href="http://research.microsoft.com/~simonpj/"&gt;Simon Peyton-Jones&lt;/a&gt;, you can learn more about that.&lt;br /&gt;
&lt;br /&gt;
Anyhow, the basic idea of Currying is to take a function with multiple arguments and transform it into a function that passes in only one argument, with the other arguments specified in the Currying function itself.  So you can think of it as a function that calls another function and returns a function.  You can think of it also as being a partial function.  So, let's actually get down to it and write some F# code to show how to do this:&lt;br /&gt;
&lt;br /&gt;
&lt;table width="100%" cellspacing="0" cellpadding="0" border="0" align="" summary="" style="color: rgb(255, 255, 255); background-color: black;"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;#light&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;n = 10&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;multiply a b = a * b&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;multiplyByFive = multiply 5&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;result = multiplyByFive 4&lt;br /&gt;
            &lt;br /&gt;
            printfn &lt;span style="color: rgb(0, 255, 0);"&gt;"result = %i"&lt;/span&gt; result&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
So, what I accomplished above is that I had a function called multiply that takes two arguments, a and b.  Then I created a currying function called multiplyByFive which curries the multiply function by supplying a five value.  Then I can call the multiplyByFive curried function with a 4 and sure enough the result is 20.&lt;br /&gt;
&lt;br /&gt;
As always, I'm always curious on how it looks through .NET Reflector to see how F# does its magic.  So, let's crack that open and take a look.  First let's look at the tree of Reflector to see what it creates for us:&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/Podwysocki/4686/r_fsharp_curriedtree.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
Now as you can see, it created the multiply function.  Then we also have a multiplyByFive FastFunc function.  The functions get stored in the namespace free area and yet the main function gets placed elsewhere.  Now, let's look at the function implementation itself.&lt;br /&gt;
&lt;br /&gt;
&lt;img alt="" src="http://geekswithblogs.net/images/geekswithblogs_net/Podwysocki/4686/r_fsharp_curriedmain.png" /&gt;&lt;br /&gt;
&lt;br /&gt;
From what you can see, it created a SampleFile class because I created a SampleFile.fs to create the curried functions.&lt;br /&gt;
&lt;br /&gt;
For those of you who are C# buffs, well, you can also do the same in C# with the new anonymous function type, System.Func in .NET 3.5.  &lt;a href="http://blogs.msdn.com/madst/"&gt;Mads Torgersen&lt;/a&gt;, the C# Program Manager, noted on his blog quite a while ago asking the question, &lt;a href="http://blogs.msdn.com/madst/archive/2007/01/23/is-c-becoming-a-functional-language.aspx"&gt;"Is C# Becoming a Functional Language?"&lt;/a&gt;.  This post was pretty great and it's unfortunate that he doesn't blog as much as he does.  Remember kids, this isn't as pretty as F# because it's not what C# is really good at, but slowly but surely, functional programming paradigms are slowly seeping into C#.&lt;br /&gt;
&lt;br /&gt;
&lt;table width="100%" cellspacing="0" cellpadding="0" border="0" align="" summary="" style="color: rgb(255, 255, 255); background-color: black;"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;span style="color: rgb(255, 153, 0);"&gt;namespace &lt;/span&gt;CSharpCurriedFunctions&lt;br /&gt;
            {&lt;br /&gt;
                &lt;span style="color: rgb(255, 153, 0);"&gt;public static class&lt;/span&gt; &lt;span style="color: rgb(255, 255, 0);"&gt;CurriedFunctionExtensions&lt;/span&gt;&lt;br /&gt;
                {&lt;br /&gt;
                    &lt;span style="color: rgb(255, 153, 0);"&gt;public static&lt;/span&gt; &lt;span style="color: rgb(51, 204, 204);"&gt;Func&lt;/span&gt;&amp;lt;A, &lt;span style="color: rgb(51, 204, 204);"&gt;Func&lt;/span&gt;&amp;lt;B, R&amp;gt;&amp;gt; Curry&amp;lt;A, B, R&amp;gt;(&lt;span style="color: rgb(255, 153, 0);"&gt;this &lt;/span&gt;&lt;span style="color: rgb(51, 204, 204);"&gt;Func&lt;/span&gt;&amp;lt;A, B, R&amp;gt; f)&lt;br /&gt;
                    {&lt;br /&gt;
                        &lt;span style="color: rgb(255, 153, 0);"&gt;return &lt;/span&gt;a =&amp;gt; b =&amp;gt; f(a, b);&lt;br /&gt;
                    }&lt;br /&gt;
            &lt;br /&gt;
                }&lt;br /&gt;
            &lt;br /&gt;
                &lt;span style="color: rgb(255, 153, 0);"&gt;class &lt;/span&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;Program&lt;/span&gt;&lt;br /&gt;
                {&lt;br /&gt;
                    &lt;span style="color: rgb(255, 153, 0);"&gt;static void&lt;/span&gt; Main(&lt;span style="color: rgb(255, 153, 0);"&gt;string&lt;/span&gt;[] args)&lt;br /&gt;
                    {&lt;br /&gt;
                        &lt;span style="color: rgb(51, 204, 204);"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;&amp;gt; multiply = (a, b)=&amp;gt; a* b;&lt;br /&gt;
                        &lt;span style="color: rgb(51, 204, 204);"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;, Func&amp;lt;&lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;&amp;gt;&amp;gt; curriedMultiply = multiply.Curry();&lt;br /&gt;
                        &lt;span style="color: rgb(51, 204, 204);"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(255, 153, 0);"&gt;int&lt;/span&gt;&amp;gt; multiplyByFive = curriedMultiply(5);&lt;br /&gt;
                        &lt;br /&gt;
                        Console.WriteLine(&lt;span style="color: rgb(0, 255, 0);"&gt;"result = {0}"&lt;/span&gt;, multiplyByFive(4));&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
If you're interested more in doing this with C#, I would suggest you head over to &lt;a href="http://diditwith.net"&gt;Dustin Campbell's blog&lt;/a&gt; and read the post about &lt;a href="http://diditwith.net/2007/08/15/TheArtOfCurrying.aspx"&gt;The Art of Currying&lt;/a&gt;.  For those who want to learn more, well, Dustin should be at &lt;a href="http://altdotnet.org/events/seattle"&gt;ALT.NET Open Spaces, Seattle&lt;/a&gt; and hopefully will submit an F# topic for us to get our heads around.  &lt;br /&gt;
&lt;br /&gt;
How useful is this in C#?  Well, time will tell, but you could imagine having some search criteria for your repository using curried functions to "overload" with values.  Anything is really possible, but as you can see, it's a lot cleaner in F# and that's where it really shines.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;The Odd Tuple&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When specifying arguments to any given function, you can specify them without parentheses much as you would in VB.NET should it be a subroutine.  This is really helpful if you want to enable currying and such.  But, you can also specify them as a &lt;a href="http://en.wikipedia.org/wiki/Tuple"&gt;tuple&lt;/a&gt;.   For the math illiterate among you, that simply means a sequence of objects of a specified type.  This you must put within parentheses.  This makes you supply all arguments at once.  A simple example of this would look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;table width="100%" cellspacing="0" cellpadding="0" border="0" align="" style="color: rgb(255, 255, 255); background-color: black;" summary=""&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;#light&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;add (a, b) = a + b&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;result = add(3, 4)&lt;br /&gt;
            &lt;br /&gt;
            printfn &lt;span style="color: rgb(0, 255, 0);"&gt;"result = %i"&lt;/span&gt; result&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
Pretty simple example and of course the result would be 7.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;Where is the Returns Department?&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As you may have noticed from the functions from above, I never really did specify any return type or return statement.  Implicitly behind the scenes, F# does that for you.  Basically when you define a function, you should indent with a tab and the last assignment becomes your return value.  The return is implicit right after the indenting is ended.  So, let's take a simplistic view of this:&lt;br /&gt;
&lt;br /&gt;
&lt;table width="100%" cellspacing="0" cellpadding="0" border="0" align="" summary="" style="color: rgb(255, 255, 255); background-color: black;"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;#light&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;addThings a b  =&lt;br /&gt;
              let c = a + b&lt;br /&gt;
              sprintf &lt;span style="color: rgb(0, 255, 0);"&gt;"result = %i"&lt;/span&gt; c&lt;br /&gt;
            &lt;br /&gt;
            &lt;span style="color: rgb(255, 153, 0);"&gt;let &lt;/span&gt;result = addThings 3 7&lt;br /&gt;
            &lt;br /&gt;
            print_string result&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
As you may notice, when using the light syntax (#light), you cannot indent, instead just use two spaces and that should suffice.  Anyhow, you may note, I was doing a simple addition and then my final assignment becomes my return value, which is using the sprintf function, which to you C buffs out there, should look familiar.&lt;br /&gt;
&lt;br style="font-weight: bold;" /&gt;
&lt;span style="font-weight: bold;"&gt;Conclusion&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;I've got a lot more on this topic quite frankly and still just covering the basics of your first F# program.  There is so much to learn on this, but these are the basic building blocks you need to make that leap into functional programming.  It's becoming more interesting year by year as our languages such as Ruby, C# and so on continue to drive towards functional programming, so it's important to grok the fundamentals.  Next time, I hope to cover some recursion stuff, functions, lists and even operators (the really fun stuff).  Until next time...&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/21/119880.aspx"&gt;&lt;img border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://geekswithblogs.net/Podwysocki/archive/2008/02/21/119880.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=119880"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119880" 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/119880.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Matthew Podwysocki</dc:creator>
            <guid>http://geekswithblogs.net/Podwysocki/archive/2008/02/21/119880.aspx</guid>
            <pubDate>Fri, 22 Feb 2008 01:48:43 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Podwysocki/comments/119880.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Podwysocki/archive/2008/02/21/119880.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Podwysocki/comments/commentRss/119880.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Podwysocki/services/trackbacks/119880.aspx</trackback:ping>
        </item>
    </channel>
</rss>