<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>techencoder &#187; Windsor</title>
	<atom:link href="http://techencoder.com/index.php/tag/windsor/feed/" rel="self" type="application/rss+xml" />
	<link>http://techencoder.com</link>
	<description>Technical ideas in a human readable format</description>
	<lastBuildDate>Wed, 01 Feb 2012 17:19:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>		<item>
		<title>Castle Windsor 2.0 in ASP.Net MVC 1.0</title>
		<link>http://techencoder.com/index.php/2009/10/castle-windsor-and-aspnet-mvc/</link>
		<comments>http://techencoder.com/index.php/2009/10/castle-windsor-and-aspnet-mvc/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 05:26:33 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Windsor]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=670</guid>
		<description><![CDATA[Consider yourself warned:  I&#8217;m just getting started with ASP.Net MVC, Dependency Injection (DI) and Inversion of Control (IoC), so this post is more for my benefit than yours. ASP.Net MVC 1.0 ASP.Net MVC 1.0 was released in March 2009. Read this tutorial to start learning it. Note that ASP.Net MVC is bin deployable which is [...]]]></description>
			<content:encoded><![CDATA[<p>Consider yourself warned:  I&#8217;m just getting started with ASP.Net MVC, Dependency Injection (DI) and Inversion of Control (IoC), so this post is <a title="Why blog? The best way to learn something is to teach it." href="http://stackoverflow.com/questions/745570/how-can-social-networking-sites-make-you-a-better-developer/745703#745703">more for my benefit than yours</a>.</p>
<p><img class="aligncenter size-full wp-image-698" title="warning-castle-windsor" src="http://techencoder.com/wp-content/uploads/2009/06/warning-castle-windsor.jpg" alt="warning-castle-windsor" width="600" height="158" /></p>
<h3>ASP.Net MVC 1.0</h3>
<p><a title="Download ASP.Net MVC" href="http://msdn.microsoft.com/en-us/library/dd394709.aspx">ASP.Net MVC 1.0</a> was released in March 2009. Read <a title="ASP.Net MVC Tutorial" href="http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx">this tutorial</a> to start learning it. Note that ASP.Net MVC is <a title="bin deploy ASP.Net MVC" href="http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx">bin deployable</a> which is very nice if you don&#8217;t want to install anything on the production web server.</p>
<h3>Inversion of Control and Castle Windsor</h3>
<p>Castle Windsor 2.0 was just released this Summer after <a title="Castle Windsor 2.0 RTM Released" href="http://ayende.com/Blog/archive/2009/05/05/castle-windsor-2.0-rtm-released.aspx">a very long development period</a>.  To start using it, <a href="http://www.castleproject.org/castle/download.html">go get the dlls</a> and reference them in your project.</p>
<p>If you are completely new to the IoC pattern, go <a href="http://msdn.microsoft.com/en-us/magazine/cc337885.aspx">read James Kovacs&#8217; article</a> and <a title="DimeCasts: Castle Windsor series" href="http://www.dimecasts.net/Casts/ByTag/Windsor%20Castle">watch these videos</a>.  They will get a typical .Net programmer up to speed pretty fast.  You should also go to <a href="http://martinfowler.com/articles/injection.html">the canonical source for IoC</a>, but frankly I learned more from the other links and I think you will too.</p>
<p>To learn how to configure the Windsor container in your project, <a title="Castle Windsor Documentation" href="http://www.castleproject.org/container/documentation/trunk/index.html">read the project&#8217;s documentation</a> and continue with this article for an example in ASP.Net MVC.</p>
<h3>Putting them Together</h3>
<p><img class="aligncenter size-full wp-image-696" title="castle-plus-aspnet-mvc" src="http://techencoder.com/wp-content/uploads/2009/06/castle-plus-aspnet-mvc.png" alt="castle-plus-aspnet-mvc" width="600" height="64" /></p>
<p>Getting Windsor to work in an ASP.Net MVC application is easy if you know what to do.  Most things are that way, huh?</p>
<p>For a bare bones integration, just follow these steps:</p>
<ol>
<li>Install ASP.NET MVC 1.0.  The <a title="Microsoft Web Platform Installer" href="http://www.microsoft.com/web/Downloads/platform.aspx">Web Platform Installer</a> is great for this and a ton of other projects.  Try it.  You&#8217;ll be glad you did.</li>
<li>Open VS 2008,  go to File-&gt;New-&gt;Project&#8230; and select the &#8220;<em>ASP.NET MVC Web Application</em>&#8221; project template.</li>
<li>Select &#8220;No&#8221; on the proceeding dialog.  Do not create a unit test project.</li>
<li><a title="Castle Windsor download page" href="http://www.castleproject.org/castle/download.html">Download</a> Castle Windsor 2.0</li>
<li>Copy the dlls (<em>Castle.DynamicProxy2, Castle.MicroKernel, Castle.Windsor and Castle.Core</em>) to your solution&#8217;s folder or a sub folder.</li>
<li>Add them as references to the web project. (Right-click the &#8220;References&#8221; folder, select &#8220;Add Reference&#8230;&#8221;, select the &#8220;Browse&#8221; tab and navigate to the dlls to add them.)</li>
<li>Add a new XML file to the web project.  Name it &#8220;windsor.config&#8221; and enter the following:</li>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--Note: Since this is a web application, all components must have a lifesytle of 'transient' or 'preWebRequest' --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;components<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #808080; font-style: italic;">&lt;!--This is where we could declaratively add components to the Windsor container if we wanted to.--&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/components<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<li>Create an interface IMessageHolder and a class MessageHolder.  (We will use this code to illustrate injecting an instance of MessageHolder into the HomeController.)</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> IMessageHolder
<span style="color: #008000;">&#123;</span>
	<span style="color: #6666cc; font-weight: bold;">string</span> GetMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MessageHolder <span style="color: #008000;">:</span> IMessageHolder
<span style="color: #008000;">&#123;</span>
	<span style="color: #008080;">#region IMessageHolder Members</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetMessage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;Welcome to ASP.NET MVC using Castle Windsor 2.0!&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080;">#endregion</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<li>Create a controller factory for Windsor:</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> WindsorControllerFactory <span style="color: #008000;">:</span> DefaultControllerFactory
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> IWindsorContainer _container<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> WindsorControllerFactory<span style="color: #008000;">&#40;</span>IWindsorContainer container<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		_container <span style="color: #008000;">=</span> container<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> IController GetControllerInstance<span style="color: #008000;">&#40;</span>Type controllerType<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>controllerType <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Force an exception message from the base class.</span>
			<span style="color: #008080; font-style: italic;">// This will be more informative than what we would get otherwise,</span>
			<span style="color: #008080; font-style: italic;">// see: http://stackoverflow.com/questions/719678/custom-controller-factory-dependency-injection-structuremap-problems-with-asp/721313#721313</span>
			<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetControllerInstance</span><span style="color: #008000;">&#40;</span>controllerType<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #008080; font-style: italic;">// Exception here ????</span>
		<span style="color: #008080; font-style: italic;">// Check the windsor configuration.</span>
		<span style="color: #008080; font-style: italic;">// Make sure that Windsor can match the component to load.</span>
		<span style="color: #0600FF; font-weight: bold;">return</span> _container<span style="color: #008000;">.</span><span style="color: #0000FF;">Resolve</span><span style="color: #008000;">&#40;</span>controllerType<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> IController<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> ReleaseController<span style="color: #008000;">&#40;</span>IController controller<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		_container<span style="color: #008000;">.</span><span style="color: #0000FF;">Release</span><span style="color: #008000;">&#40;</span>controller<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<li>Open Global.asax.cs and replace it with the following:</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MvcApplication <span style="color: #008000;">:</span> HttpApplication
<span style="color: #008000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;</span>
	<span style="color: #008080; font-style: italic;">/// This has to be static, because more than one instance</span>
	<span style="color: #008080; font-style: italic;">/// of the HttpApplication can potentially be created.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/remarks&gt;</span>
	<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> IWindsorContainer _container<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RegisterRoutes<span style="color: #008000;">&#40;</span>RouteCollection routes<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		routes<span style="color: #008000;">.</span><span style="color: #0000FF;">IgnoreRoute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;{resource}.axd/{*pathInfo}&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		routes<span style="color: #008000;">.</span><span style="color: #0000FF;">MapRoute</span><span style="color: #008000;">&#40;</span>
			<span style="color: #666666;">&quot;Default&quot;</span>, <span style="color: #008080; font-style: italic;">// Route name</span>
			<span style="color: #666666;">&quot;{controller}/{action}/{id}&quot;</span>, <span style="color: #008080; font-style: italic;">// URL with parameters</span>
			<span style="color: #008000;">new</span> <span style="color: #008000;">&#123;</span>controller <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Home&quot;</span>, action <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Index&quot;</span>, id <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#125;</span> <span style="color: #008080; font-style: italic;">// Parameter defaults</span>
			<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Application_Start<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		RegisterRoutes<span style="color: #008000;">&#40;</span>RouteTable<span style="color: #008000;">.</span><span style="color: #0000FF;">Routes</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		InitializeWindsor<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Setup the MVC framework to use our Windsor controller factory.</span>
		ControllerBuilder<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetControllerFactory</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> WindsorControllerFactory<span style="color: #008000;">&#40;</span>_container<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> InitializeWindsor<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_container <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			_container <span style="color: #008000;">=</span> Build<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;windsor.config&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IWindsorContainer Build<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> configPath<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		var resource <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileResource<span style="color: #008000;">&#40;</span>configPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		var interperter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlInterpreter<span style="color: #008000;">&#40;</span>resource<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		var container <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WindsorContainer<span style="color: #008000;">&#40;</span>interperter<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Register controllers</span>
		container<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span>AllTypes
					   <span style="color: #008000;">.</span><span style="color: #0000FF;">Of</span><span style="color: #008000;">&lt;</span>Controller<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
					   <span style="color: #008000;">.</span><span style="color: #0000FF;">FromAssembly</span><span style="color: #008000;">&#40;</span>Assembly<span style="color: #008000;">.</span><span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008080; font-style: italic;">/* Modify the name with which the component is registered
		See: http://blog.andreloker.de/post/2009/03/28/ASPNET-MVC-with-Windsor-programmatic-controller-registration.aspx */</span>
					   <span style="color: #008000;">.</span><span style="color: #0000FF;">Configure</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">LifeStyle</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transient</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Named</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">.</span><span style="color: #0000FF;">Implementation</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Register all other types.</span>
		container<span style="color: #008000;">.</span><span style="color: #0000FF;">Register</span><span style="color: #008000;">&#40;</span>
			Component<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">For</span><span style="color: #008000;">&lt;</span>IMessageHolder<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ImplementedBy</span><span style="color: #008000;">&lt;</span>MessageHolder<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LifeStyle</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transient</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF; font-weight: bold;">return</span> container<span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<li>Add a constructor to the HomeController and give it an IMessageHolder parameter.</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #008000;">&#91;</span>HandleError<span style="color: #008000;">&#93;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> HomeController <span style="color: #008000;">:</span> Controller
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> IMessageHolder _holder<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> HomeController<span style="color: #008000;">&#40;</span>IMessageHolder holder<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            _holder <span style="color: #008000;">=</span> holder<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult Index<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            ViewData<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;Message&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> _holder<span style="color: #008000;">.</span><span style="color: #0000FF;">GetMessage</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult About<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>
Since IMessageHolder is registered with Windsor, the container will resolve IMessageHolder to an instance of MessageHolder at run-time.  This is called <a href="http://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a> because the HomeController dependency is injected through the constructor.  Of course, you could do this without an IoC container such as Windsor, but in larger (real world) applications the container will greatly simplify the process of managing dependencies, which means you have a better chance of keeping things <a href="http://en.wikipedia.org/wiki/Loose_coupling">loosely coupled</a> and falling into <a href="http://www.codinghorror.com/blog/archives/000940.html">the pit of success</a>.
</p>
<p>
Notice also that we display the message in Index() to verify that the Windsor container is giving us a valid instance of the type registered for IMessageHolder.  This is just a simple way to see the result of what occurred.
</p>
<li>Run the application and you should see the message on the home page.  Click <a href='http://techencoder.com/wp-content/uploads/2009/10/mvcwebapplication1.zip'>here</a> to download the sample project.</li>
<p><img src="http://techencoder.com/wp-content/uploads/2009/10/aspnet-and-windsor-integration.png" alt="aspnet-and-windsor-integration" title="aspnet-and-windsor-integration" width="600" height="404" class="aligncenter size-full wp-image-956" />
</ol>
<p>
<a href='http://techencoder.com/wp-content/uploads/2009/10/mvcwebapplication1.zip'>Project Source Code</a> for this post.
</p>
<p>I hope that this walk-through helps someone get started with Windsor.  It really is an incredible project to learn and if used correctly it will make your programs much better.  Have fun with it and Happy Programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/10/castle-windsor-and-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

