<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Tim Barcz - IoC</title>
    <link>http://www.timbarcz.com/blog/</link>
    <description>My Code is My Craft</description>
    <image>
      <url>http://www.timbarcz.com/blog/content/binary/channelImage.jpg</url>
      <title>Tim Barcz - IoC</title>
      <link>http://www.timbarcz.com/blog/</link>
    </image>
    <language>en-us</language>
    <copyright>Tim Barcz</copyright>
    <lastBuildDate>Mon, 13 Jul 2009 03:13:46 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>blog@timbarcz.com</managingEditor>
    <webMaster>blog@timbarcz.com</webMaster>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=5dfc88b7-a5e3-4bf9-8616-ad9ee961f464</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,5dfc88b7-a5e3-4bf9-8616-ad9ee961f464.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,5dfc88b7-a5e3-4bf9-8616-ad9ee961f464.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=5dfc88b7-a5e3-4bf9-8616-ad9ee961f464</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last week <a href="http://www.lostechies.com/blogs/jimmy_bogard">Jimmy Bogard</a> posted
why he believed the <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/07/03/how-not-to-do-dependency-injection-in-nerddinner.aspx">dependency
injection pattern appearing in the NerdDinner application was flawed</a>.  I
want to take the opportunity to say the pattern in <a href="http://nerddinner.codeplex.com/">NerdDinner</a> really
isn't that bad and I want to explain why.  Before I go on I will say that I entirely
agree with Jimmy's thoughts on the pattern for my own code and you won't find the
anti-pattern Jimmy describes in my code.
</p>
        <p>
So why isn't the pattern <strong>that</strong> bad? I see Dependency Injection as
generally having at least two major benefits:
</p>
        <ul>
          <li>
Testability 
</li>
          <li>
Flexibility (most often achieved by using an IoC container) 
</li>
        </ul>
        <p>
The pattern under scrutiny in NerdDinner accounts for testability, of which I am a
firm believer in, but lacks in flexibility.  If I had to rank the two items above,
I would rank testability above flexibility.  Testability is a core tenet on which
I stand for with the code I write.
</p>
        <h2>Explain Again Why NerdDinner is "Flawed"
</h2>
        <p>
To recap here is the code from Jimmy's post:
</p>
        <div>
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">public</span>
              <span style="color: rgb(0, 0, 255);">class</span> SearchController
: Controller {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span> IDinnerRepository
dinnerRepository;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 4:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 5:</span>
              <span style="color: rgb(0, 128, 0);">//</span>
            </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 6:</span>
              <span style="color: rgb(0, 128, 0);">//
Dependency Injection enabled constructors</span>
            </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 7:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 8:</span>
              <span style="color: rgb(0, 0, 255);">public</span> SearchController()</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 9:</span> : <span style="color: rgb(0, 0, 255);">this</span>(<span style="color: rgb(0, 0, 255);">new</span> DinnerRepository())
{</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 10:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 11:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 12:</span>
              <span style="color: rgb(0, 0, 255);">public</span> SearchController(IDinnerRepository
repository) {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 13:</span> dinnerRepository
= repository;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 14:</span> }</pre>
          </div>
        </div>
        <p>
The first constructor, when called, "news up" a new DinnerRepository() and passes
it into another constructor on the same object which is generally considered "poor
man's dependency injection".  This pattern is considered bad (this an anti-pattern)
because some, of which Jimmy is one, believe you shouldn't "new up" new objects this
way, choosing instead to allow a container to inject the primal dependency. 
The problem I have with this view is that for many applications a container is overkill. 
Many applications will only have one concrete implementation of a class, so in many
ways this constructor and the object creation could be seen as providing a sensible
default to the application, allowing the consumer to create an instance without worry
about what else the object needs.
</p>
        <h2>But You Said You Don't Write Your Code that Way?
</h2>
        <p>
Absolutely correct, I don't write my code this way.  Why? I already have a container
set up in my application and so to not use it would be foolish.  We also have
a complex application/domain, sometimes with multiple concrete implementations of
an interface.
</p>
        <p>
I used to write code this way using this pattern. Really. I don't feel ashamed to
say so. The reason we adopted the dependency injection (DI) pattern in the application
where this overloaded constructor "anti-pattern" was used was because DI allows for
testability, and as I have previously mentioned, this "anti-pattern" doesn't stand
in the way of testing.
</p>
        <p>
I further believe that most developers must make a certain progression on their own. 
We can write and share our experiences but in the end every developer out there must
some day be convinced in their own time. \They must come to the conclusion on their
own, like I did, that using "poor man's injection" will work for many many scenarios
but will get ugly fast in others.
</p>
        <h2>What's Really Wrong with "Poor Man's Dependency Injection"?
</h2>
        <p>
For simple applications/domain, typically not much (again, my opinion).  For
complex domain the issue you will run into is maintainability/flexibility.  If
you get to a complex domain and you use the pattern from NerdDinner you will someday
have:
</p>
        <div>
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">public</span> SearchController(<span style="color: rgb(0, 0, 255);">new</span> SearchService(<span style="color: rgb(0, 0, 255);">new</span> SearchLogService(<span style="color: rgb(0, 0, 255);">new</span> Logger()), <span style="color: rgb(0, 0, 255);">new</span> SearchRepository(<span style="color: rgb(0, 0, 255);">new</span> SessionBuilder()), <span style="color: rgb(0, 0, 255);">new</span> SearchResultFormatter(<span style="color: rgb(0, 0, 255);">new</span> FormatProvider())))</pre>
          </div>
        </div>
        <p>
Ugly for sure.  This is why it's generally considered an "Anti-Pattern". 
However for applications where the controller is the service-layer and controllers
therefore use repositories, I would not be too concerned with the use of this pattern.
</p>
        <p>
While Jimmy did a great job fixing the application, you first have to believe the
application needed fixing.  Which of course, depends on context.  How big/complex
is your application/domain?  Jimmy's application/domain is sufficiently complex
as is mine, yours may not be.  For NerdDinner I believe the pattern was a suitable
choice.
</p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=5dfc88b7-a5e3-4bf9-8616-ad9ee961f464" />
      </body>
      <title>Why There's Nothing Wrong With Dependency Injection in NerdDinner</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,5dfc88b7-a5e3-4bf9-8616-ad9ee961f464.aspx</guid>
      <link>http://www.timbarcz.com/blog/WhyTheresNothingWrongWithDependencyInjectionInNerdDinner.aspx</link>
      <pubDate>Mon, 13 Jul 2009 03:13:46 GMT</pubDate>
      <description>&lt;p&gt;
Last week &lt;a href="http://www.lostechies.com/blogs/jimmy_bogard"&gt;Jimmy Bogard&lt;/a&gt; posted
why he believed the &lt;a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/07/03/how-not-to-do-dependency-injection-in-nerddinner.aspx"&gt;dependency
injection pattern appearing in the NerdDinner application was flawed&lt;/a&gt;.&amp;nbsp; I
want to take the opportunity to say the pattern in &lt;a href="http://nerddinner.codeplex.com/"&gt;NerdDinner&lt;/a&gt; really
isn't that bad and I want to explain why.&amp;nbsp; Before I go on I will say that I entirely
agree with Jimmy's thoughts on the pattern for my own code and you won't find the
anti-pattern Jimmy describes in my code.
&lt;/p&gt;
&lt;p&gt;
So why isn't the pattern &lt;strong&gt;that&lt;/strong&gt; bad? I see Dependency Injection as
generally having at least two major benefits:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Testability 
&lt;/li&gt;
&lt;li&gt;
Flexibility (most often achieved by using an IoC container) 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The pattern under scrutiny in NerdDinner accounts for testability, of which I am a
firm believer in, but lacks in flexibility.&amp;nbsp; If I had to rank the two items above,
I would rank testability above flexibility.&amp;nbsp; Testability is a core tenet on which
I stand for with the code I write.
&lt;/p&gt;
&lt;h2&gt;Explain Again Why NerdDinner is "Flawed"
&lt;/h2&gt;
&lt;p&gt;
To recap here is the code from Jimmy's post:
&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; SearchController
: Controller {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; IDinnerRepository
dinnerRepository;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 4:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;//&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;//
Dependency Injection enabled constructors&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 7:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 8:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SearchController()&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 9:&lt;/span&gt; : &lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DinnerRepository())
{&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 10:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 11:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 12:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SearchController(IDinnerRepository
repository) {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 13:&lt;/span&gt; dinnerRepository
= repository;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 14:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The first constructor, when called, "news up" a new DinnerRepository() and passes
it into another constructor on the same object which is generally considered "poor
man's dependency injection".&amp;nbsp; This pattern is considered bad (this an anti-pattern)
because some, of which Jimmy is one, believe you shouldn't "new up" new objects this
way, choosing instead to allow a container to inject the primal dependency.&amp;nbsp;
The problem I have with this view is that for many applications a container is overkill.&amp;nbsp;
Many applications will only have one concrete implementation of a class, so in many
ways this constructor and the object creation could be seen as providing a sensible
default to the application, allowing the consumer to create an instance without worry
about what else the object needs.
&lt;/p&gt;
&lt;h2&gt;But You Said You Don't Write Your Code that Way?
&lt;/h2&gt;
&lt;p&gt;
Absolutely correct, I don't write my code this way.&amp;nbsp; Why? I already have a container
set up in my application and so to not use it would be foolish.&amp;nbsp; We also have
a complex application/domain, sometimes with multiple concrete implementations of
an interface.
&lt;/p&gt;
&lt;p&gt;
I used to write code this way using this pattern. Really. I don't feel ashamed to
say so. The reason we adopted the dependency injection (DI) pattern in the application
where this overloaded constructor "anti-pattern" was used was because DI allows for
testability, and as I have previously mentioned, this "anti-pattern" doesn't stand
in the way of testing.
&lt;/p&gt;
&lt;p&gt;
I further believe that most developers must make a certain progression on their own.&amp;nbsp;
We can write and share our experiences but in the end every developer out there must
some day be convinced in their own time. \They must come to the conclusion on their
own, like I did, that using "poor man's injection" will work for many many scenarios
but will get ugly fast in others.
&lt;/p&gt;
&lt;h2&gt;What's Really Wrong with "Poor Man's Dependency Injection"?
&lt;/h2&gt;
&lt;p&gt;
For simple applications/domain, typically not much (again, my opinion).&amp;nbsp; For
complex domain the issue you will run into is maintainability/flexibility.&amp;nbsp; If
you get to a complex domain and you use the pattern from NerdDinner you will someday
have:
&lt;/p&gt;
&lt;div&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SearchController(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SearchService(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SearchLogService(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Logger()), &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SearchRepository(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SessionBuilder()), &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SearchResultFormatter(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; FormatProvider())))&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Ugly for sure.&amp;nbsp; This is why it's generally considered an "Anti-Pattern".&amp;nbsp;
However for applications where the controller is the service-layer and controllers
therefore use repositories, I would not be too concerned with the use of this pattern.
&lt;/p&gt;
&lt;p&gt;
While Jimmy did a great job fixing the application, you first have to believe the
application needed fixing.&amp;nbsp; Which of course, depends on context.&amp;nbsp; How big/complex
is your application/domain?&amp;nbsp; Jimmy's application/domain is sufficiently complex
as is mine, yours may not be.&amp;nbsp; For NerdDinner I believe the pattern was a suitable
choice.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=5dfc88b7-a5e3-4bf9-8616-ad9ee961f464" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,5dfc88b7-a5e3-4bf9-8616-ad9ee961f464.aspx</comments>
      <category>ASP.NET MVC Framework</category>
      <category>IoC</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=8493245c-62af-4c83-9470-0f04e0a667e8</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,8493245c-62af-4c83-9470-0f04e0a667e8.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,8493245c-62af-4c83-9470-0f04e0a667e8.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=8493245c-62af-4c83-9470-0f04e0a667e8</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I don't want to be a wet blanket, but someone's got to put a stop to the IoC love
fest going on out there.  An Inversion of Control (IoC) container , for those
of you were aren't yet familiar, allows you to retrieve instances of objects at runtime. 
A relatively common solution to a common problem. In the .NET world there is no lack
of choices of IoC containers:
</p>
        <ul>
          <li>
            <a href="http://www.castleproject.org/container/index.html">Castle's Winsdor/MicroKernel</a>
          </li>
          <li>
            <a href="http://structuremap.sourceforge.net/Default.htm">StructureMap</a>
          </li>
          <li>
            <a href="http://www.springframework.net/">Spring.NET</a>
          </li>
          <li>
            <a href="http://code.google.com/p/autofac/">AutoFac</a>
          </li>
          <li>
            <a href="http://ninject.org/">Ninject</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/cc468366.aspx">Unity</a>
          </li>
          <li>
            <a href="http://funq.codeplex.com/">Funq</a>
          </li>
        </ul>
        <p>
(I won't go fully into IoC, but If you'd like more resource you can read <a href="http://martinfowler.com/articles/injection.html">Martin
Fowler's article on the subject</a> or post specific questions in the comments or
contact me through.  Read on, there is value here in this post for you.)
</p>
        <p>
          <strong>Let me state clearly now, IoC containers are a means to an end and NOT a feature
of your application.</strong> The goal is to have loosely coupled applications, IoC
containers help get you there, but you can absolutely have a loosely coupled application
without an IoC container (see the <a href="http://www.dofactory.com/Patterns/Patterns.aspx">Gang
of Four creational patterns</a>).
</p>
        <p>
Occasionally I'll hear some comment about IoC and how great a certain container is
or how an application would be so much better if another, sexier, container was used. 
Here are some recent <a href="http://www.twitter.com">tweets</a> that illustrate:
</p>
        <ul>
          <li>
Man i love #StructureMap, always finding new things i can do, and have fun doing them 
</li>
          <li>
really need to look at structuremap, but we''ve invested a lot into castle with our
own facilities/resolvers/etc 
</li>
          <li>
Ninject is da bomb! 
</li>
          <li>
Switched from Windsor MicroKernel to Ninject in 10KLOC project in &lt; 1 hour by creating
a little proxy. Now to complete the conversion. 
</li>
          <li>
It is a talk on Castle Windsor so i guess Ninject will not do. 
</li>
          <li>
Can't imagine why somebody would use Ninject beside the fact that it's PURE AND UTTER
AWESOME. Yeah! Ninject FTW. 
</li>
        </ul>
        <p>
Some of the statements above are probably innocuous, but some rub me slightly the
wrong way.  Specifically the two comments above about switching from one container
to another. There are probably times when the choice of one container over another
makes sense, but I would bet that these scenarios are the exception and not the rule.
</p>
        <p>
Choosing one container over another won't make your application a success, the architecture,
or lack there of, will have far more of a say on your application than will your container
choice. As yoda might say, "The container you choose does not a good app make". 
</p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=8493245c-62af-4c83-9470-0f04e0a667e8" />
      </body>
      <title>Your IoC Container Choice is Not a Feature of Your Application</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,8493245c-62af-4c83-9470-0f04e0a667e8.aspx</guid>
      <link>http://www.timbarcz.com/blog/YourIoCContainerChoiceIsNotAFeatureOfYourApplication.aspx</link>
      <pubDate>Mon, 30 Mar 2009 02:56:27 GMT</pubDate>
      <description>&lt;p&gt;
I don't want to be a wet blanket, but someone's got to put a stop to the IoC love
fest going on out there.&amp;#160; An Inversion of Control (IoC) container , for those
of you were aren't yet familiar, allows you to retrieve instances of objects at runtime.&amp;#160;
A relatively common solution to a common problem. In the .NET world there is no lack
of choices of IoC containers:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.castleproject.org/container/index.html"&gt;Castle's Winsdor/MicroKernel&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://structuremap.sourceforge.net/Default.htm"&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://code.google.com/p/autofac/"&gt;AutoFac&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://msdn.microsoft.com/en-us/library/cc468366.aspx"&gt;Unity&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://funq.codeplex.com/"&gt;Funq&lt;/a&gt; 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
(I won't go fully into IoC, but If you'd like more resource you can read &lt;a href="http://martinfowler.com/articles/injection.html"&gt;Martin
Fowler's article on the subject&lt;/a&gt; or post specific questions in the comments or
contact me through.&amp;#160; Read on, there is value here in this post for you.)
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Let me state clearly now, IoC containers are a means to an end and NOT a feature
of your application.&lt;/strong&gt; The goal is to have loosely coupled applications, IoC
containers help get you there, but you can absolutely have a loosely coupled application
without an IoC container (see the &lt;a href="http://www.dofactory.com/Patterns/Patterns.aspx"&gt;Gang
of Four creational patterns&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
Occasionally I'll hear some comment about IoC and how great a certain container is
or how an application would be so much better if another, sexier, container was used.&amp;#160;
Here are some recent &lt;a href="http://www.twitter.com"&gt;tweets&lt;/a&gt; that illustrate:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Man i love #StructureMap, always finding new things i can do, and have fun doing them 
&lt;/li&gt;
&lt;li&gt;
really need to look at structuremap, but we''ve invested a lot into castle with our
own facilities/resolvers/etc 
&lt;/li&gt;
&lt;li&gt;
Ninject is da bomb! 
&lt;/li&gt;
&lt;li&gt;
Switched from Windsor MicroKernel to Ninject in 10KLOC project in &amp;lt; 1 hour by creating
a little proxy. Now to complete the conversion. 
&lt;/li&gt;
&lt;li&gt;
It is a talk on Castle Windsor so i guess Ninject will not do. 
&lt;/li&gt;
&lt;li&gt;
Can't imagine why somebody would use Ninject beside the fact that it's PURE AND UTTER
AWESOME. Yeah! Ninject FTW. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Some of the statements above are probably innocuous, but some rub me slightly the
wrong way.&amp;#160; Specifically the two comments above about switching from one container
to another. There are probably times when the choice of one container over another
makes sense, but I would bet that these scenarios are the exception and not the rule.
&lt;/p&gt;
&lt;p&gt;
Choosing one container over another won't make your application a success, the architecture,
or lack there of, will have far more of a say on your application than will your container
choice. As yoda might say, &amp;quot;The container you choose does not a good app make&amp;quot;. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=8493245c-62af-4c83-9470-0f04e0a667e8" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,8493245c-62af-4c83-9470-0f04e0a667e8.aspx</comments>
      <category>IoC</category>
      <category>Rant</category>
      <category>Tools</category>
      <category>Windsor</category>
    </item>
    <item>
      <trackback:ping>http://www.timbarcz.com/blog/Trackback.aspx?guid=e5bc8f32-f714-45c4-aac4-7379e8f0a351</trackback:ping>
      <pingback:server>http://www.timbarcz.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.timbarcz.com/blog/PermaLink,guid,e5bc8f32-f714-45c4-aac4-7379e8f0a351.aspx</pingback:target>
      <dc:creator>Tim Barcz</dc:creator>
      <wfw:comment>http://www.timbarcz.com/blog/CommentView,guid,e5bc8f32-f714-45c4-aac4-7379e8f0a351.aspx</wfw:comment>
      <wfw:commentRss>http://www.timbarcz.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e5bc8f32-f714-45c4-aac4-7379e8f0a351</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Windsor will stitch together objects for you at runtime based on what components have
been registered.  When you ask for an instance of an object from the Windsor/MicroKernel
it will return the object using the constructor it can satisfy.
</p>
        <p>
I ran into a problem the other day when I wanted to create an object that accepted
three types, the third was a non-primitive that I didn't control.  <a href="http://www.castleproject.org">Castle's
website</a> goes into some detail on this in their <a href="http://www.castleproject.org/container/documentation/trunk/usersguide/compparams.html">documentation
on Windsor/MicroKernel</a>:
</p>
        <blockquote>
          <div>
            <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 1:</span>
                <span style="color: #0000ff">&lt;</span>
                <span style="color: #800000">configuration</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 2:</span>  </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 3:</span>
                <span style="color: #0000ff">&lt;</span>
                <span style="color: #800000">components</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 4:</span>
                <span style="color: #0000ff">&lt;</span>
                <span style="color: #800000">component</span>
                <span style="color: #ff0000">id</span>
                <span style="color: #0000ff">="smtp.sender"</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 5:</span>
                <span style="color: #ff0000">service</span>
                <span style="color: #0000ff">="Namespace.IEmailSender,
AssemblyName"</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 6:</span>
                <span style="color: #ff0000">type</span>
                <span style="color: #0000ff">="Namespace.SmtpMailSender,
AssemblyName"</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 7:</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 8:</span>
                <span style="color: #0000ff">&lt;</span>
                <span style="color: #800000">parameters</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 9:</span>
                <span style="color: #0000ff">&lt;</span>
                <span style="color: #800000">port</span>
                <span style="color: #0000ff">&gt;</span>10<span style="color: #0000ff">&lt;/</span><span style="color: #800000">port</span><span style="color: #0000ff">&gt;</span></pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 10:</span>
                <span style="color: #0000ff">&lt;</span>
                <span style="color: #800000">host</span>
                <span style="color: #0000ff">&gt;</span>smtphost<span style="color: #0000ff">&lt;/</span><span style="color: #800000">host</span><span style="color: #0000ff">&gt;</span></pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 11:</span>
                <span style="color: #0000ff">&lt;/</span>
                <span style="color: #800000">parameters</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 12:</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 13:</span>
                <span style="color: #0000ff">&lt;/</span>
                <span style="color: #800000">component</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 14:</span>
                <span style="color: #0000ff">&lt;/</span>
                <span style="color: #800000">components</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
                <span style="color: #606060"> 15:</span>  </pre>
              <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
                <span style="color: #606060"> 16:</span>
                <span style="color: #0000ff">&lt;/</span>
                <span style="color: #800000">configuration</span>
                <span style="color: #0000ff">&gt;</span>
              </pre>
            </div>
          </div>
        </blockquote>
        <p>
the problem I was running into is what if you have a third parameter, which isn't
a primitive?  I have the following signature:
</p>
        <div>
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">public</span> CommunicationGateway(<span style="color: #0000ff">string</span> host, <span style="color: #0000ff">int</span> port,
Encoding encoding)</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> {</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span>
              <span style="color: #0000ff">this</span>.host
= host;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span>
              <span style="color: #0000ff">this</span>.port
= port;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 5:</span>
              <span style="color: #0000ff">this</span>.encoding
= encoding;</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span> }</pre>
          </div>
        </div>
        <p>
The example above fits quite nicely until I hit the third parameter.  How do
I define what that third parameter should be in Windsor given that it's not a class
that I control nor a primitive type? This felt like it should be easy, but I could
not find the information I needed on the Castle website.  I got some help from
Castle committer <a href="http://geekswithblogs.net/dsellers/Default.aspx">Dru Sellers</a>. 
In the end Dru pointed me to a very simple solution; register the type and pass it
in using the service lookup notation, ${}
</p>
        <div>
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">component</span>
              <span style="color: #ff0000">id</span>
              <span style="color: #0000ff">="CommunicationGateway"</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span>
              <span style="color: #ff0000">service</span>
              <span style="color: #0000ff">="ABCCompany.ICommunicationGateway,
ABCCompany"</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 3:</span>
              <span style="color: #ff0000">type</span>
              <span style="color: #0000ff">="ABCCompany.CommunicationGateway,
ABCCompany"</span>
              <span style="color: #0000ff">&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span>
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">parameters</span>
              <span style="color: #0000ff">&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 5:</span>
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">host</span>
              <span style="color: #0000ff">&gt;</span>#{Host}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">host</span><span style="color: #0000ff">&gt;</span></pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span>
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">port</span>
              <span style="color: #0000ff">&gt;</span>#{Port}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">port</span><span style="color: #0000ff">&gt;</span></pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 7:</span>
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">encoding</span>
              <span style="color: #0000ff">&gt;</span>${Encoding}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">encoding</span><span style="color: #0000ff">&gt;</span></pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span>
              <span style="color: #0000ff">&lt;/</span>
              <span style="color: #800000">parameters</span>
              <span style="color: #0000ff">&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 9:</span>
              <span style="color: #0000ff">&lt;/</span>
              <span style="color: #800000">component</span>
              <span style="color: #0000ff">&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 10:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 11:</span>
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">component</span>
              <span style="color: #ff0000">id</span>
              <span style="color: #0000ff">="Encoding"</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 12:</span>
              <span style="color: #ff0000">service</span>
              <span style="color: #0000ff">="System.Text.Encoding,
mscorlib"</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
              <span style="color: #606060"> 13:</span>
              <span style="color: #ff0000">type</span>
              <span style="color: #0000ff">="System.Text.UTF8Encoding,
mscorlib"</span>
              <span style="color: #0000ff">&gt;</span>
            </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 14:</span>
              <span style="color: #0000ff">&lt;/</span>
              <span style="color: #800000">component</span>
              <span style="color: #0000ff">&gt;</span>
            </pre>
          </div>
        </div>
        <p>
You can see from above that I'm registering a component with the service System.Text.Encoding
and supplying UTF8Encoding as the implementation.  Now I can use a strongly-typed
System.Text.Encoding object and have it configurable in my Windsor Configuration,
much more elegant than using a string (primitive-type) and hoping it works.  
</p>
        <p>
Thanks Dru!
</p>
        <img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=e5bc8f32-f714-45c4-aac4-7379e8f0a351" />
      </body>
      <title>Windsor Config Parameters With Non-Primitive Types</title>
      <guid isPermaLink="false">http://www.timbarcz.com/blog/PermaLink,guid,e5bc8f32-f714-45c4-aac4-7379e8f0a351.aspx</guid>
      <link>http://www.timbarcz.com/blog/WindsorConfigParametersWithNonPrimitiveTypes.aspx</link>
      <pubDate>Thu, 18 Sep 2008 18:01:09 GMT</pubDate>
      <description>&lt;p&gt;
Windsor will stitch together objects for you at runtime based on what components have
been registered.&amp;#160; When you ask for an instance of an object from the Windsor/MicroKernel
it will return the object using the constructor it can satisfy.
&lt;/p&gt;
&lt;p&gt;
I ran into a problem the other day when I wanted to create an object that accepted
three types, the third was a non-primitive that I didn't control.&amp;#160; &lt;a href="http://www.castleproject.org"&gt;Castle's
website&lt;/a&gt; goes into some detail on this in their &lt;a href="http://www.castleproject.org/container/documentation/trunk/usersguide/compparams.html"&gt;documentation
on Windsor/MicroKernel&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;components&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;component&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;smtp.sender&amp;quot;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; &lt;span style="color: #ff0000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Namespace.IEmailSender,
AssemblyName&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Namespace.SmtpMailSender,
AssemblyName&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;port&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;10&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;port&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 10:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;host&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;smtphost&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;host&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 11:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;parameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 12:&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 13:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;component&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 14:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;components&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 16:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
the problem I was running into is what if you have a third parameter, which isn't
a primitive?&amp;#160; I have the following signature:
&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CommunicationGateway(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; host, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; port,
Encoding encoding)&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.host
= host;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.port
= port;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.encoding
= encoding;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
The example above fits quite nicely until I hit the third parameter.&amp;#160; How do
I define what that third parameter should be in Windsor given that it's not a class
that I control nor a primitive type? This felt like it should be easy, but I could
not find the information I needed on the Castle website.&amp;#160; I got some help from
Castle committer &lt;a href="http://geekswithblogs.net/dsellers/Default.aspx"&gt;Dru Sellers&lt;/a&gt;.&amp;#160;
In the end Dru pointed me to a very simple solution; register the type and pass it
in using the service lookup notation, ${}
&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;component&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CommunicationGateway&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; &lt;span style="color: #ff0000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ABCCompany.ICommunicationGateway,
ABCCompany&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ABCCompany.CommunicationGateway,
ABCCompany&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;host&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;#{Host}&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;host&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;port&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;#{Port}&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;port&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;${Encoding}&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;parameters&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;component&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 11:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;component&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Encoding&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 12:&lt;/span&gt; &lt;span style="color: #ff0000"&gt;service&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.Text.Encoding,
mscorlib&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 13:&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.Text.UTF8Encoding,
mscorlib&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 14:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;component&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
You can see from above that I'm registering a component with the service System.Text.Encoding
and supplying UTF8Encoding as the implementation.&amp;#160; Now I can use a strongly-typed
System.Text.Encoding object and have it configurable in my Windsor Configuration,
much more elegant than using a string (primitive-type) and hoping it works.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Thanks Dru!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.timbarcz.com/blog/aggbug.ashx?id=e5bc8f32-f714-45c4-aac4-7379e8f0a351" /&gt;</description>
      <comments>http://www.timbarcz.com/blog/CommentView,guid,e5bc8f32-f714-45c4-aac4-7379e8f0a351.aspx</comments>
      <category>Caslte</category>
      <category>IoC</category>
      <category>Tips &amp; Tricks</category>
    </item>
  </channel>
</rss>