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

<channel>
	<title>Code Distillers</title>
	<atom:link href="http://www.codedistillers.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codedistillers.com</link>
	<description>Software Craftsmenship on a .net world</description>
	<lastBuildDate>Mon, 14 Jan 2013 11:21:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>DUX &#8211; Developer User Experience</title>
		<link>http://www.codedistillers.com/rui/2013/01/14/dux-developer-user-experience/</link>
		<comments>http://www.codedistillers.com/rui/2013/01/14/dux-developer-user-experience/#comments</comments>
		<pubDate>Mon, 14 Jan 2013 08:00:15 +0000</pubDate>
		<dc:creator>rui</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=129</guid>
		<description><![CDATA[Sometimes, I wonder why things are not simple and expressive. One thing that I try to advocate for many years is something that I should call DUX &#8211; Development User Experience. It means what it should mean : the user experience while you are doing your development. We know that good software is hard to [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, I wonder why things are not simple and expressive.</p>
<p>One thing that I try to advocate for many years is something that I should call DUX &#8211; Development User Experience. It means what it should mean : the user experience while you are doing your development.</p>
<p>We know that good software is hard to achieve and that most of the times people care only about what is visible. Crafting all the parts of the code in the right way is also important. The final end user experience is not the only part&#8230;</p>
<p>When you build frameworks or lower level components, even if their target is to be used by developers for higher level software, never forget that you still users! Your users are the developers working with your libraries.</p>
<p>Why do I complain? Because DUX is also an important part of the things you should care when you are building libraries. Framework developers usually though about:</p>
<ul>
<li>Try to provide the functions needed for the framework with a defined priority order (maybe defined by marketing guys&#8230;)</li>
<li>Try to provide as much functions as possible because a richer framework is better than a framework providing a small set of things.</li>
<li>Use some unit tests for internal use because most people do.</li>
<li>Try to care about performance because a framework should do</li>
<li>Try to fit as much as possible in the current ecosystem</li>
<li>&#8230;certainly a lot of other things</li>
</ul>
<p>I don&#8217;t know if all these things are the main reason I prefer to use open source libraries but in most cases these ones provide a slightly different results when they are realized with a decentralized unordered team:</p>
<ul>
<li>Functions are provided because people really needs them</li>
<li>Delivery and functionalities are not subsidiaries of the market</li>
<li>You can control functionalities with the unit tests provided and also see how it works (most of the times this is much more efficient than a regular documentation&#8230;)</li>
</ul>
<p>Another good point with open source is that the good and the bad are automatically currated by the community. If your framework doesn&#8217;t deserve enough needs, if it is not enough clear about it&#8217;s usage and so on, it will die. Simple and efficient.</p>
<p>Frameworks have to be simple and fun to use. The .Net world has a lot of legacy stuff and history that tends to be complicated by essence because it takes its roots in entreprise. Alternatively languages like Ruby have things simple and expressive mostly because it is a developer to developer platform with pragmatism in mind.</p>
<p>Take a simple exemple. Suppose, you are building a shell application. You want to print messages and draw some lines to present things clearly, like this:</p>
<p>&nbsp;</p>
<pre class="brush: shell">--------------------------------------------------------------
-- My App (c) 2013
--------------------------------------------------------------</pre>
<p>In C# to build lines like this, you should write all the line in a string and print it like that:</p>
<pre class="brush: csharp">Console.WriteLine("--------------------------------------------------------------");</pre>
<p>Or with an iteration if you want to get more reusability :</p>
<pre class="brush:csharp">public string Repeat(string pattern, int timesToRepeat)
	{
		string[] resultArray = new string[timesToRepeat];
		string result = pattern;
		for (int i = 1; i &lt; timesToRepeat; i++)
		{
			result = result+pattern;
		}
		return result;
	}
...
Console.WriteLine(Repeat("-",80));</pre>
<p>Instead of that, in the ruby world, you just do that:</p>
<pre class="brush:ruby">puts "-" * 80</pre>
<p>Which literally means : &#8220;put in standard output the string &#8216;-&#8217; repeated 80 times. Which one sounds better for you?</p>
<p><strong>Attention</strong>: <em>please note that I am a .Net developer, we are just trying to talk about DUX, I am far than saying that Ruby is better than C#, yeap?</em></p>
<p>Btw, C# is a very high level platform and you have a lot of better things but that&#8217;s not the problem here. And In fact you should get more fluent things with a simple extension method like that:</p>
<pre class="brush:csharp">public static string Repeat(this string pattern, int timesToRepeat)
	{
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i &lt; timesToRepeat; i++)
		{
			sb.Append(pattern);
		}
		return sb.ToString();
	}
...
Console.WriteLine("-".Repeat(80));</pre>
<p>If you want a shortest way to achieve that you should also try:</p>
<pre class="brush:csharp">String.Join("",Enumerable.Repeat("-",80))</pre>
<p>&nbsp;</p>
<p>Never forget that software is complicated by essence, so, don&#8217;t help this complication, try to make things clean even if your audience are developers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/rui/2013/01/14/dux-developer-user-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net Web dev Mac &#8211; Nuget, Monodevelop and Nancy</title>
		<link>http://www.codedistillers.com/rui/2013/01/09/net-web-dev-on-mac-nuget-monodevelop-nancy/</link>
		<comments>http://www.codedistillers.com/rui/2013/01/09/net-web-dev-on-mac-nuget-monodevelop-nancy/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 09:57:45 +0000</pubDate>
		<dc:creator>rui</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Macosx]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Nancy]]></category>
		<category><![CDATA[Nuget]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=99</guid>
		<description><![CDATA[Basic Support In the Beginning Managing binaries, dependencies and packages is such an important point that it is unbelievable  that it takes 10 years to get something like Nuget on .Net from Microsoft&#8230; If you are running Mono for .Net web development on your Mac, it is not better regarding this point&#8230; It was painful with MonoDevelop [...]]]></description>
			<content:encoded><![CDATA[<h2>Basic Support</h2>
<h3>In the Beginning</h3>
<p>Managing binaries, dependencies and packages is such an important point that it is unbelievable  that it takes 10 years to get something like Nuget on .Net from Microsoft&#8230;</p>
<p>If you are running Mono for .Net web development on your Mac, it is not better regarding this point&#8230;</p>
<p>It was painful with MonoDevelop was the lack of support for Nuget.</p>
<p>We can do things by hand since v2 of Nuget (and before 1.7 btw) because you can use nuget.exe from mono command line but as it wasn&#8217;t integrated in solutions and projects it only helps you get binaries.</p>
<p>But let&#8217;s see how to setup Nuget on mono.</p>
<h3>Install &amp; configure Nuget</h3>
<p>First download the las exe:</p>
<pre class="brush: shell">curl -O -L  http://nuget.org/nuget.exe</pre>
<p>As Nuget is a .Net binary, you need to launch it via mono. If your installation is ok &#8211; and it should with the installer -, you are able to launch mono from every path in your shell. Note also that you need to specify the framework 4 runtime compatibility to make it work properly. So start the nugget exe, just execute this line:</p>
<pre class="brush: shell">mono --runtime=v4.0 Nuget.exe [then follow your nuget args]</pre>
<p>In order to make this work from every, I should advise you to create an executable shell script that handle that.</p>
<p>In the folder you downloaded Nuget, copy it to /usr/local/bin:</p>
<pre class="brush: shell">cp Nuget.exe /usr/local/bin</pre>
<p>Create a new file for your command, just name it nuget to get the same semantics:</p>
<pre class="brush: shell">touch nuget</pre>
<p>Edit your file and just copy/paste this code:</p>
<pre class="brush: shell">#!/bin/sh
# add a simple 'nuget' command to Mac OS X shell under Mono
PATH=/usr/local/bin:$PATH
mono --runtime=v4.0 /usr/local/bin/NuGet.exe $*</pre>
<p>Then give the correct execution rights to your file:</p>
<pre class="brush: shell">sudo chmod +x nuget</pre>
<p>Then open a new console and try nuget (with a nuget help for exemple). The good point is that you can now use Nuget from everywhere!</p>
<p>You should also have a default config path working with NuGet, if you don&#8217;t have one created automatically, create a new fresh one</p>
<p>Local config should be stored at:</p>
<pre class="brush: shell">~/.config/NuGet/Nuget.config</pre>
<p>Once you have this, you can play with nuget, with your own repositories too, but you still closed in the command shell.</p>
<p>If you work with MonoDevelop, you have to create your package folder, your packages config file and then reference your binaries manually. It&#8217;s not an ideal configuration but that&#8217;s better than nohting <img src='http://www.codedistillers.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<h2>Nuget support on Monodevelop</h2>
<h3>Install</h3>
<p>This morning my eyes flashed after a tweet of David Fowler:</p>
<div id="attachment_113" class="wp-caption alignnone" style="width: 310px"><a href="https://twitter.com/davidfowl/status/288879652238409728" target="_blank"><img class="size-medium wp-image-113" title="David Fowler tweet about nuget monodevelop support" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_37-300x150.png" alt="David Fowler tweet about nuget monodevelop support" width="300" height="150" /></a><p class="wp-caption-text">nuget monodevelop support</p></div>
<p>Ok, let&#8217;s see what is it about?</p>
<p>This is about an Addin written by Matt Ward. You can find the sources on <a title="Monodevelop nuget addin" href="https://github.com/mrward/monodevelop-nuget-addin" target="_blank">his github </a></p>
<p>&nbsp;</p>
<p>You can build it and install it by your own, but Matt did the things well and provided a Monodevelop addin channel with this:</p>
<p><a href="http://mrward.github.com/monodevelop-nuget-addin-repository/3.0.5/main.mrep" rel="nofollow" target="_top">http://mrward.github.com/monodevelop-nuget-addin-repository/3.0.5/main.mrep</a></p>
<p>Click on Monodevelop, then Add-in manager. Select Gallery and manage repositories:</p>
<div id="attachment_115" class="wp-caption alignnone" style="width: 460px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_09_58.png"><img class="size-full wp-image-115" title="Manage addin repositories" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_09_58.png" alt="monodevelop addin repositories" width="450" height="195" /></a><p class="wp-caption-text">monodevelop addin repositories</p></div>
<p>Then click [Add] and paste the url:</p>
<div id="attachment_116" class="wp-caption alignnone" style="width: 561px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_10_01.png"><img class="size-full wp-image-116" title="Add repository definition url" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_10_01.png" alt="Add repository definition url" width="551" height="264" /></a><p class="wp-caption-text">Add repository definition url</p></div>
<p>Once you have it, you should get a new addin available:</p>
<div id="attachment_117" class="wp-caption alignnone" style="width: 475px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_10_03.png"><img class="size-full wp-image-117" title="new addin" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_10_03.png" alt="new addin" width="465" height="157" /></a><p class="wp-caption-text">new addin</p></div>
<p>Select it and install.</p>
<h3>Let&#8217;s try a web project with Nancy!</h3>
<p>First, create a new empty ASP.NET web project:</p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_03.png"><img class="size-medium wp-image-110 " title="New empty asp.net project" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_03-300x160.png" alt="New empty asp.net project" width="300" height="160" /></a><p class="wp-caption-text">New empty asp.net project</p></div>
<p>Before playing with Nuget, Add a web.config file because it is not provided by default with this project template:</p>
<div id="attachment_111" class="wp-caption alignnone" style="width: 528px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_06.png"><img class="size-full wp-image-111 " title="add web.config" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_06.png" alt="add web.config" width="518" height="205" /></a><p class="wp-caption-text">add web.config on monodevelop</p></div>
<p>Then you should try to run it but obviously you&#8217;ll get nothing.</p>
<p>Now, right click on references:</p>
<div id="attachment_108" class="wp-caption alignnone" style="width: 357px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_07_15.png"><img class="size-full wp-image-108" title="References with Nuget" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_07_15.png" alt="References with Nuget" width="347" height="166" /></a><p class="wp-caption-text">References with Nuget</p></div>
<p>So cool! We have now Nuget resources just here! Select Manage Nuget Packages.</p>
<p>You&#8217;ll have a box just as the one you use to use under Visual Studio (if you are in click-click mode instead of the Package manager console which is a Powershell host of course&#8230;):</p>
<div id="attachment_112" class="wp-caption alignnone" style="width: 624px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_07.png"><img class="size-full wp-image-112" title="Nuget box" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_08_07.png" alt="Nuget box" width="614" height="593" /></a><p class="wp-caption-text">Nuget box</p></div>
<p>Just start with typing &#8216;Nancy.host&#8217;, select &#8216;Nancy.Hosting.Aspnet&#8217; then Add. You can see in the messages, that it handles correctly the download of Nancy.dll too.</p>
<p>Then add a new class to your project with your HomeModule with a simple test route:</p>
<pre class="brush: csharp">using System;
using Nancy;

namespace Demo
{
	public class HomeModule : NancyModule
	{
		public HomeModule ()
		{
			Get ["/(.*)"] = _ =&gt; "Yes it works!";
		}
	}
}</pre>
<p>That&#8217;s supposed to be enough for now. Build and run. Guess what? it doesn&#8217;t work.</p>
<p>Why? Remember that nuget installation features under Visual Studio are full of Powershell and transforming files are part of it. So, remember that when you install something with Monodevelop Nuget you don&#8217;t have the transforms like web.config updates!</p>
<p><strong>UPDATE</strong>: Thanks to author Matt Ward that points an explication for that in the comments: &#8220;PowerShell is not actually needed for the web.config transform to be applied. It is not currently working in the MonoDevelop NuGet addin due to a bug. <strong>The addin is not detecting the project is a web project and ignoring the transform</strong>. Transforms for app.config files are currently working.&#8221;</p>
<p>Then open your web.config file and update  it  to setup Nancy handler:</p>
<pre class="brush: csharp">&lt;?xml version="1.0"?&gt;
&lt;!--
Web.config file for Demo.
The settings that can be used in this file are documented at
http://www.mono-project.com/Config_system.web and

http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx

--&gt;
&lt;configuration&gt;
&lt;system.web&gt;
&lt;compilation defaultLanguage="C#" debug="true" <strong>targetFramework="4.0"</strong>&gt;
&lt;assemblies&gt;
&lt;/assemblies&gt;
&lt;/compilation&gt;
&lt;customErrors mode="RemoteOnly"&gt;
&lt;/customErrors&gt;
&lt;authentication mode="None"&gt;
&lt;/authentication&gt;
&lt;authorization&gt;
&lt;allow users="*" /&gt;
&lt;/authorization&gt;
&lt;httpHandlers&gt;
<strong>&lt;add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/&gt;</strong>
&lt;/httpHandlers&gt;
&lt;trace enabled="false" localOnly="true" pageOutput="false" requestLimit="10" traceMode="SortByTime" /&gt;
&lt;sessionState mode="InProc" cookieless="false" timeout="20" /&gt;
&lt;globalization requestEncoding="utf-8" responseEncoding="utf-8" /&gt;
&lt;pages&gt;
&lt;/pages&gt;
&lt;/system.web&gt;
<strong>&lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;validation validateIntegratedModeConfiguration="false"/&gt; &lt;handlers&gt; &lt;add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*"/&gt; &lt;/handlers&gt; &lt;/system.webServer&gt;</strong>
&lt;/configuration&gt;</pre>
<p>Re-run it and now it works!</p>
<h3>How easy to do .Net web!</h3>
<p>Just to finish with that and show you how cool it is, relaunch Nuget manager and Add also Nancy.ViewEngines.Razor, jQuery and Twitter bootstrap.</p>
<p>Create Folders Views/Home and add a new html file called &#8220;Index.cshtml&#8221;</p>
<p>If you&#8217;re like me and never remember the right syntax for bootstrapping things, keep a visible bookmark to Twitter bootstrap page and take this one as exemple:</p>
<p><a title="Twitter bootstrap sample" href="http://twitter.github.com/bootstrap/examples/marketing-narrow.html" target="_blank">http://twitter.github.com/bootstrap/examples/marketing-narrow.html</a></p>
<p>Copy paste the source on your file as exemple, then update it to fit your config, paths and update the main block (just extracts with updated things ):</p>
<pre class="brush: html">...
&lt;title&gt;Nuget on MonoDevelop&lt;/title&gt;
...
&lt;link href="/Content/bootstrap.css" rel="stylesheet"&gt;
...
&lt;link href="/Content/bootstrap-responsive.css" rel="stylesheet"&gt;
...
&lt;div class="jumbotron"&gt;
&lt;h1&gt;Nuget on MonoDevelop!&lt;/h1&gt;
&lt;p class="lead"&gt;
Get started with .Net Web dev on Mac with Monodevelop, Nuget, Nancy and Bootstrap!
&lt;/p&gt;
&lt;p&gt;Generated at @Model.Generated by @Model.Author
&lt;a class="btn btn-large btn-success" href="#"&gt;It's alive&lt;/a&gt;
&lt;/div&gt;</pre>
<p>Then update your home module to return the Razor view and with a small model class to test passing things to the view</p>
<pre class="brush: csharp">public class HomeModule : NancyModule
	{
		public HomeModule ()
		{
		Get ["/(.*)"] = _ =&gt;
                   View ["Index", new HomeInfo (
                          DateTime.Now, "Rui Carvalho")];
		}
	}

	public class HomeInfo
	{
		public DateTime Generated { get; private set; }
		public string Author { get; private set; }

		public HomeInfo (DateTime generated, string author)
		{
			Generated = generated;
			Author = author;
		}
	}</pre>
<p>Run it and enjoy more happy dappy path of web development with Nancy, Nuget and Mono on your Mac</p>
<div id="attachment_120" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_10_47.png"><img class="size-medium wp-image-120" title="Nancy with twitter bootstrap" src="http://www.codedistillers.com/wp-content/uploads/2013/01/CAP-Monodevelop-Nuget_09_01_13_10_47-300x243.png" alt="Nancy with twitter bootstrap" width="300" height="243" /></a><p class="wp-caption-text">Nancy with twitter bootstrap</p></div>
<p>cheers!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/rui/2013/01/09/net-web-dev-on-mac-nuget-monodevelop-nancy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>When .gitignore doesn&#8217;t want to work</title>
		<link>http://www.codedistillers.com/tja/2012/11/01/when-gitignore-doesnt-want-to-work/</link>
		<comments>http://www.codedistillers.com/tja/2012/11/01/when-gitignore-doesnt-want-to-work/#comments</comments>
		<pubDate>Thu, 01 Nov 2012 21:50:58 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Technical Posts]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=92</guid>
		<description><![CDATA[There are times you feel so very stupid because you can&#8217;t do a simple thing… like for example making work a .gitignore file. I don&#8217;t know how much time I had spent looking into the guts of git commands before I realised what I&#8217;ve done. As you know you can&#8217;t really create .gitignore from Windows (or [...]]]></description>
			<content:encoded><![CDATA[<p>There are times you feel so very stupid because you can&#8217;t do a simple thing… like for example making work a .<strong>gitignore</strong> file. I don&#8217;t know how much time I had spent looking into the guts of git commands before I realised what I&#8217;ve done. As you know you can&#8217;t really create .<strong>gitignore</strong> from Windows (or I don&#8217;t know how to do it). Every time I need this file, I copied it from another place, another project. This time I had a brilliant idea of creating it from the command line like this :</p>
<p><em>echo &#8220;packages/&#8221; &gt; .gitignore</em></p>
<p>Well, that&#8217;s the problem. The file doesn&#8217;t work because <strong>it&#8217;s not encoded with UTF-8</strong>. So you have to encode and save it and everything works as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/tja/2012/11/01/when-gitignore-doesnt-want-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Is HTML a valid media-type for building web sites with RESTful API ?</title>
		<link>http://www.codedistillers.com/tja/2012/10/29/is-html-a-valid-media-type-for-building-web-sites-with-restful-api/</link>
		<comments>http://www.codedistillers.com/tja/2012/10/29/is-html-a-valid-media-type-for-building-web-sites-with-restful-api/#comments</comments>
		<pubDate>Mon, 29 Oct 2012 08:14:00 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[ASP.NET Web Api]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful API]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=66</guid>
		<description><![CDATA[This is the question I’ve been asking myself while confronted to a problem of building a web site and RESTful API at the same time. I’ve been told that I can’t build one and have both. Why ? HTML is just another media-type but what is generally used when building web sites is the capacity [...]]]></description>
			<content:encoded><![CDATA[<p>This is the question I’ve been asking myself while confronted to a problem of building a web site and RESTful API at the same time. I’ve been told that I can’t build one and have both. Why ? HTML is just another media-type but what is generally used when building web sites is the capacity of <strong>templated view generation</strong> which is much more then simple HTML resource representation. And yes, I know, the ambiguity is even more emphasized when we try to chose a right framework for the task at hand. In short, the guideline is; if you want HTML based web site then use ASP.NET MVC and for JSON/XML support use rather ASP.NET Web API or another framework like Nancy (I’m speaking here for the .NET world). Well, I don’t want make my choice based on that criteria. Let’s go deeper to see what options we have.</p>
<p>Almost all the “RESTful” web service I’ve seen until now are constructed around two main media-types; JSON and XML. Less employed but still interesting in some scenarios is Atom. The most prevailing is the JSON media-type because of the increasing number of Js frameworks that have showed up since few years for building client side web sites.</p>
<h5>But what about HTML ? </h5>
<p>HTML is here since the very beginning of the web but still not very used in RESTful api as media-type. When we look back on the recent framework releases for building RESTful API in the .NET world we notice that HTML templated view generation is not supported OOTB. While for example <a href="http://www.asp.net/web-api" target="_blank">ASP.NET Web API</a> or <a href="http://nancyfx.org/" target="_blank">Nancy</a> allows you to do what you want by bending a little bit a framework (Nancy just have another Nuget package) you still have a feeling that HTML is something that doesn’t fit very well to the RESTful API design. </p>
<p>HTML from the very beginning was meant to represent informative documents that contains links to related documents which perfectly fit to the principle of media-type for REST API design. As identified by R. Fielding related to the “<em>Web architectural style</em>”, one of the six constraints that has to be respected is <strong>Uniform Interface</strong>. The interactions between clients, servers and other network based intermediaries depends on the uniformity of their interfaces. If any of the components stray from the established standards, then the Web’s communication system breaks down.</p>
<h6>HTML and Uniform interface</h6>
<p>The uniform interface boils down to the four constraints identified by R. Fielding :</p>
<ol>
<li>Identification of resources </li>
<li>Manipulation of resources through representations </li>
<li>Self-descriptive messages </li>
<li>Hypermedia as the engine of application state (HATEOAS) </li>
</ol>
<p>Let’s see how it is related to the HTML media-type.</p>
<p><strong>Identification of resources</strong> : Each&#160; resource should be addressed by a unique identifier such as a URI. So this constraint is not directly related to the HTML media-type.</p>
<p><strong>Manipulation of resources through representations</strong> :&#160; Clients manipulate representations of resources. The same exact resource can be represented to different clients in different ways. For example, a document might be represented as HTML to a web browser, and as JSON to an automated program. <strong>The key idea here is that the representation is a way to interact with the resource but it is not the resource itself</strong>. This conceptual distinction allows the resource to be represented in different ways and formats without ever changing its identifier. The HTML is a valid representation of resource.</p>
<p><strong>Self-descriptive messages</strong> : A resource’s <em>desired state</em> can be represented within a client’s request message. A resource’s <em>current state</em> may be represented within the response message that comes back from a server. The <strong>self-descriptive messages</strong> may include <em>metadata</em> to convey additional details regarding the resource state, the representation format and size, and the message itself. Moreover through the HTTP headers it’s possible to organize the various types of metadata into uniform fields. The HTML is a valid media-type as self-descriptive message.</p>
<p><strong>Hypermedia as the engine of application state (HATEOAS)</strong> : A resource’s state representation includes links to related resources. Links are the threads that weave the Web together by allowing users to traverse information and applications in a meaningful and directed manner. The presence, or absence, of a link on a page is an important part of the resource’s current state. HTML has hyperlinks so this constraint is also valid.</p>
<p>There is no point to prove that HTML is valid as representation of the resource. It’s from the very beginning of the web. After all, if your web browser couldn’t render HTML documents, the human Web would have been stunted from the start. Typically, resource representations such as HTML are <em>meant for human consumption via a web browser</em>. Browsers are the most common computer agents on the Web today. Another software agent consumes the <em>XML or JSON representations as part of a business-to-business process</em>.</p>
<h5>RESTful API and templated view generation.</h5>
<p>Here we go straight to the point. The main confusion among the developer community is not the HTML as a media-type but the constraints that are directly related to the web sites view construction. I talk here about .NET platform but I think the same constraints apply everywhere.</p>
<p>Templated view generation is a mean of transforming html templates for web pages filling them with data (often from different sources) into HTML pages. The problem is that :</p>
<p><strong>HTML page != HTML representation of the resource</strong></p>
<p>What does this statement imply ? In fact very much. Because when we’re building a web site, what we’re used to see in our browser is not just a simple HTML representation of a specific resource but often very complex HTML view construction mixing up the data from different sources and using child html views for the name of reusability. This means : </p>
<ul>
<li>MasterPages/Layouts are used to guarantee a consistent look and feel of the rendered HTML. </li>
<li>PartialViews are used for keeping in one place common html code and using it in different parent views. </li>
<li>URI is not used as resource identification but as handler of page generation using very often mixed resources of different kind or different data view projection to present user with the UI for the functional use case at hand (dashbord, shoping cart, item detail page, etc.) </li>
<li>Web site navigation is here for broader user experience of the web site, not just for the purpose of the resource state transformation (HATEOAS). </li>
<li>The presentation of the HTML is altered with CSS. </li>
<li>Other client frameworks like js are used. </li>
<li>Many other reasons </li>
</ul>
<p>Going further with the analysis we see that achieving both i.e <strong>building RESTful API and html based web site is almost impossible</strong>. If we would like to go down this path it means that underlying framework we use to build our RESTful api with, in all the cases, is just returning resource representation in Json/Xml/Html with it’s hypermedia links. But in the case of the web site the page construction (master pages, and content page composition, etc.) should be handled by something else that is not of the responsibility of the RESTful API framework and that is used later in the pipeline. Well, as far as I know this doesn’t exist yet.</p>
<h5>Can I build one to have both ?</h5>
<p>Or, could I use HTML as the representation of the resource to build a web site with. Moreover, thanks to the content-negotiation I would also have a RESTful API. That is a fair question to answer. I think that I we go down the path of ASP.NET API and Nancy, templated view generation is far more complex than just a resource representation in the given format like HTML for example. A REST resource has it’s own semantics and business meaning that doesn’t necessarily align with the UI considerations and especially doesn’t care about how it is presented to the user.</p>
<p>I understand now why ASP.NET Web Api has it’s own existence compared to ASP.NET. Many people were ranting after the release of the ASP.NET Web Api that Microsoft is confusing the developer community because both ASP.NET MVC and API seemed to handle many common responsibilities. But in fact no.</p>
<p>This means that for me bothering with HTML as media-type has no value. I still want build one and have both. That’s why my choice will be to build a RESTFul API with a framework like ASP.NET Web API, Nancy or event Node.js serving a JSON/XML. I want use a templated view generation on the server side. I’d rather use a view composition on the client side with JS framework like AngularJs. I would have then the best of two worlds <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&#39;œil" src="http://www.codedistillers.com/wp-content/uploads/2012/10/wlEmoticon-winkingsmile.png" />; less code to write and greater encapsulation of responsibilities i.e APIs serves just resources, view and templates are composed on the client.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/tja/2012/10/29/is-html-a-valid-media-type-for-building-web-sites-with-restful-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebNet12 Conference &#8211; Feedback, slides, photos</title>
		<link>http://www.codedistillers.com/rui/2012/10/24/webnet12-conference-feedback-slides-photos/</link>
		<comments>http://www.codedistillers.com/rui/2012/10/24/webnet12-conference-feedback-slides-photos/#comments</comments>
		<pubDate>Wed, 24 Oct 2012 16:30:50 +0000</pubDate>
		<dc:creator>rui</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[NancyFX]]></category>
		<category><![CDATA[Photos]]></category>
		<category><![CDATA[Slides]]></category>
		<category><![CDATA[Web.Net]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=69</guid>
		<description><![CDATA[Last week-end, I was part of the Web.Net conference in Milano. It was the first Edition of the event and I really feel it was a success! Big thanks to Simone Chiaretta(@simonech) and Ugo Lattanzi(@imperugo) for starting all this, for the big organisation work and to be such kind people I really hope to help [...]]]></description>
			<content:encoded><![CDATA[<p>Last week-end, I was part of the Web.Net conference in Milano. It was the first Edition of the event and I really feel it was a success!</p>
<p>Big thanks to Simone Chiaretta(@simonech) and Ugo Lattanzi(@imperugo) for starting all this, for the big organisation work and to be such kind people <img src='http://www.codedistillers.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I really hope to help them next time and hope that we can manage to create the event in Paris next year. </p>
<p>For this edition, I did a presentation about &#8220;Simplicity&#8221;, why it matters and how to achieve it with tiny frameworks and tools.</p>
<p>You can find the slides just below.</p>
<p><iframe src="http://fr.slideshare.net/slideshow/embed_code/14857715" width="427" height="356" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen> </iframe>
<div style="margin-bottom:5px"> <strong> <a href="http://fr.slideshare.net/rhwy/simplicity-develop-modern-web-apps-with-tiny-frameworks-and-tools" title="Simplicity - develop modern web apps with tiny frameworks and tools" target="_blank">Simplicity &#8211; develop modern web apps with tiny frameworks and tools</a> </strong> from <strong><a href="http://fr.slideshare.net/rhwy" target="_blank">Rui Carvalho</a></strong> </div>
<p>I&#8217;ll publish the sources for all my samples as soon as I&#8217;ll organise them better and clean a little bit. You&#8217;ll find them here:</p>
<p><a href="https://github.com/rhwy/SimplicityWeb.Net" title="https://github.com/rhwy/SimplicityWeb.Net" target="_blank">https://github.com/rhwy/SimplicityWeb.Net</a></p>
<p>***</p>
<p>After the conference, this means sunday, I finally took some time to enjoy the city. There is a lot of things to see in Milano, but you can find most of them in the old city center. In that way, I went for a walk from the hotel to these hotests point for about 4 hours. </p>
<p>You can find below some pics, really nice time <img src='http://www.codedistillers.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<div id="slideshow_embed_div"><object width="500" height="375"><param name="flashvars" value="offsite=true&amp;lang=fr-fr&amp;page_show_url=%2Fphotos%2F11301148%40N00%2Fsets%2F72157631831106840%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2F11301148%40N00%2Fsets%2F72157631831106840%2F&amp;set_id=72157631831106840&amp;jump_to="><param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=122138"><param name="allowFullScreen" value="true"><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=122138" allowfullscreen="true" flashvars="offsite=true&amp;lang=fr-fr&amp;page_show_url=%2Fphotos%2F11301148%40N00%2Fsets%2F72157631831106840%2Fshow%2F&amp;page_show_back_url=%2Fphotos%2F11301148%40N00%2Fsets%2F72157631831106840%2F&amp;set_id=72157631831106840&amp;jump_to=" width="500" height="375"></object></div>
<p>Another thing that was nice in the trip was the transportation. Nowadays, we use to take plane as a default solution, but sometimes train should be a really nice alternative! It was direct, starting from Paris, nearest station from house, then a very nice and comfortable trip of 7 hours while you can work, have lunch, then you arrive in the near center of Milano. That was really a good choice for me, and also a real joy of crossing the Alps by train.</p>
<p>Again, it was very nice to see all this people, a special mention for nice discussions with Chris Massey (@camassey), Robert Mühsig (@robert0muehsig), Kris (@Kvdm) and so much more!</p>
<p>Hope to see Milan again next year and hope to see you all for the 2013 Paris Edition <img src='http://www.codedistillers.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>cheers!<br />

<a href='http://www.codedistillers.com/rui/2012/10/24/webnet12-conference-feedback-slides-photos/a5zkbdmcaaaxlgg/' title='Milano Garibaldi station, just before leaving'><img width="150" height="150" src="http://www.codedistillers.com/wp-content/uploads/2012/10/A5zKBdMCAAAXLgG-150x150.jpg" class="attachment-thumbnail" alt="Milano Garibaldi station, just before leaving" title="Milano Garibaldi station, just before leaving" /></a>
<a href='http://www.codedistillers.com/rui/2012/10/24/webnet12-conference-feedback-slides-photos/a5z8ktgccaaqhex/' title='In the middle of the Alps, from the train window'><img width="150" height="150" src="http://www.codedistillers.com/wp-content/uploads/2012/10/A5z8kTgCcAAqheX-150x150.jpg" class="attachment-thumbnail" alt="In the middle of the Alps, from the train window" title="In the middle of the Alps, from the train window" /></a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/rui/2012/10/24/webnet12-conference-feedback-slides-photos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SOLID &#8211; A small refactory sequence on ConfArt</title>
		<link>http://www.codedistillers.com/rui/2012/07/18/solid-a-small-refactory-sequence-onconfart/</link>
		<comments>http://www.codedistillers.com/rui/2012/07/18/solid-a-small-refactory-sequence-onconfart/#comments</comments>
		<pubDate>Wed, 18 Jul 2012 00:55:20 +0000</pubDate>
		<dc:creator>rui</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[solid]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=61</guid>
		<description><![CDATA[p { margin-bottom: 9px; } code, pre { font-family: Monaco, Andale Mono, Courier New, monospace; } code { background-color: #fee9cc; color: rgba(0, 0, 0, 0.75); padding: 1px 3px; font-size: 12px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; } pre { display: block; padding: 14px; margin: 0 0 18px; line-height: 16px; font-size: 11px; border: 1px solid #d9d9d9; [...]]]></description>
			<content:encoded><![CDATA[<style>
p {
    margin-bottom: 9px;
}
code, pre {
    font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
    background-color: #fee9cc;
    color: rgba(0, 0, 0, 0.75);
    padding: 1px 3px;
    font-size: 12px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
}
pre {
    display: block;
    padding: 14px;
    margin: 0 0 18px;
    line-height: 16px;
    font-size: 11px;
    border: 1px solid #d9d9d9;
    white-space: pre-wrap;
    word-wrap: break-word;
}
pre code {
    background-color: #fff;
    color:#737373;
    font-size: 11px;
    padding: 0;
}
</style>
<p>I am working on a small library to help working with some dynamic stuff, but the target is mainly to use dynamics to simplify configuration and exchange data when types are not needed. This started as a demo project, but as I used some differents classes and techniques in different projects I tought it should be interesting to share all that in a full functional library and, at least it should be interesting help to learn a few things.</p>
<p>By the way, this is not the target of this first post about it, it&rsquo;s only about refactoring. As this starts in a demo mode, most of the code was not really well constructed, even if it is almost well tested and most parts were done in TDD mode.</p>
<p>Let&rsquo;s analyse a method I have:</p>
<pre><code>private  void InitializeSetter()
{
    var expBoxy = _setterExpression.Body;

    if (expBoxy.NodeType == ExpressionType.Convert)
    {
        var convertExp = (UnaryExpression)expBoxy;
        var operand = (MemberExpression)convertExp.Operand;

        if (operand.Member is PropertyInfo)
        {
            PropertyInfo pi = typeof(T).GetProperty(operand.Member.Name);
            _setter = pi.GetValueSetter&lt;T&gt;();
        }

    }
    else if (expBoxy.NodeType == ExpressionType.MemberAccess)
    {
        var operand = (MemberExpression)expBoxy;

        if (operand.Member is PropertyInfo)
        {
            PropertyInfo pi = typeof(T).GetProperty(operand.Member.Name);
            _setter = pi.GetValueSetter&lt;T&gt;();
        }

    }
    else
    {
        throw new InvalidOperationException("Expression is not valid to set a property, should be something like x=&gt;x.Name");
    }
}
</code></pre>
<p>This is not too long, but when I get back reviewing the code, it is almost complicated. And why it is complicated because this ends up with too much responsabilities and this does not use the full power of open close principles&hellip;</p>
<p>To complete this method, this is also the properties of this class and the constructor:</p>
<pre><code>private Action&lt;T, object&gt; _setter;
private readonly Expression&lt;Func&lt;T, object&gt;&gt; _setterExpression;
private readonly ConfigurationMappingsBase&lt;T&gt; _source;

public Action&lt;string, Action&lt;T, object&gt;&gt; UpdateSource { private get; set; }

public PropertySetterExpression(ConfigurationMappingsBase&lt;T&gt; source, Expression&lt;Func&lt;T, object&gt;&gt; setterExpression)
{
    _source = source;
    _setterExpression = setterExpression;
    InitializeSetter();
}
</code></pre>
<p>Ok, Let&rsquo;s analyse the code now.</p>
<p>I get all my properties from the constructor, that&rsquo;s the good design point, but just in the constructor It begins to fail. It relays too much on &lsquo;Void&rsquo; methods to set magicaly stuff and that matters!</p>
<p>As, the goal of <code>InitializeSetter</code> is to initialize the member <code>_setter</code> with some content of the member <code>_setterExpression</code> Let&rsquo;s do it in another way:</p>
<pre><code>public PropertySetterExpression(ConfigurationMappingsBase&lt;T&gt; source, Expression&lt;Func&lt;T, object&gt;&gt; setterExpression)
{
    _source = source;
    _setterExpression = setterExpression;
    _setter = InitializeSetter(_setterExpression);
}

private Action&lt;T, object&gt; InitializeSetter(Expression&lt;Func&lt;T, object&gt;&gt; expression)
{
    var expBoxy = _setterExpression.Body;
    return null; //temp hack
}
</code></pre>
<p>Ok, it compiles again and I have no more magical void method stuff, and I should test now this method (But I don&rsquo;t want to, as I consider it as an internal mechanism and I made it private, but that&rsquo;s another debate <img src='http://www.codedistillers.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>But, what do I in the method? I get the Body &#8211; which is of type <code>Expression</code> and I work with it. Shouldn&rsquo;t it be better to pass it directly and avoid a new var?</p>
<pre><code>public PropertySetterExpression(ConfigurationMappingsBase&lt;T&gt; source, Expression&lt;Func&lt;T, object&gt;&gt; setterExpression)
{
    _source = source;
    _setterExpression = setterExpression;
    _setter = InitializeSetter(_setterExpression.Body);
}

private Action&lt;T, object&gt; InitializeSetter(Expression expression)
{
    if (expression.NodeType == ExpressionType.Convert)
    {
        var convertExp = (UnaryExpression)expression;
    }
    else if (expression.NodeType == ExpressionType.MemberAccess)
    {
        var operand = (MemberExpression)expression;
    }
    else
    {
        throw new InvalidOperationException("Expression");
    }
}
</code></pre>
<p>Now, What did I do with this expression? I rely on my procedural methods deeply printed in my reptilian cortex to make an <code>if-then-else</code> construct to do some work based on the type information of the expression and then cast it to the right type&hellip;That&rsquo;s not too much object oriented no? And more, it violates the OCP&hellip;</p>
<p>Let&rsquo;s rewrite it in an object way:</p>
<pre><code>public PropertySetterExpression(ConfigurationMappingsBase&lt;T&gt; source, Expression&lt;Func&lt;T, object&gt;&gt; setterExpression)
{
    _source = source;
    _setterExpression = setterExpression;
    _setter = InitializeSetter(_setterExpression.Body);
}

private Action&lt;T, object&gt; InitializeSetter(UnaryExpression expression)
{
    var operand = (MemberExpression)expression.Operand;

    if (operand.Member is PropertyInfo)
    {
        var pi = typeof(T).GetProperty(operand.Member.Name);
        return pi.GetValueSetter&lt;T&gt;();
    }
    return null;
}

private Action&lt;T, object&gt; InitializeSetter(MemberExpression expression)
{
    if (expression.Member is PropertyInfo)
    {
        PropertyInfo pi = typeof(T).GetProperty(expression.Member.Name);
        _setter = pi.GetValueSetter&lt;T&gt;();
    }
    return null;
}

private Action&lt;T, object&gt; InitializeSetter(Expression expression)
{
    throw new InvalidOperationException("Expression");
}
</code></pre>
<p>Well, much better. But, I focuses me much more on what the code do right now, this can be simplified again:</p>
<p>The code of the unary expression, gets the member and do the same code that the member expression one, and as I had to return a value, I had to set to null, this means that my original code should failed If I don&rsquo;t fall in the right path (or at least my _setter value should be null). Let&rsquo;s do a last refactor:</p>
<pre><code>public PropertySetterExpression(ConfigurationMappingsBase&lt;T&gt; source, Expression&lt;Func&lt;T, object&gt;&gt; setterExpression)
{
    _source = source;
    _setterExpression = setterExpression;
    _setter = InitializeSetter(_setterExpression.Body);
}

private Action&lt;T, object&gt; InitializeSetter(UnaryExpression expression)
{
    return InitializeSetter(expression.Operand);
}

private Action&lt;T, object&gt; InitializeSetter(MemberExpression expression)
{
    if (expression.Member is PropertyInfo)
    {
        var pi = typeof(T).GetProperty(expression.Member.Name);
        return pi.GetValueSetter&lt;T&gt;();
    }
    return InitializeSetter(expression);
}

private Action&lt;T, object&gt; InitializeSetter(Expression expression)
{
    throw new InvalidOperationException("Expression");
}
</code></pre>
<p>I am now quite happy with that, and that&rsquo;s all for the theorical part <img src='http://www.codedistillers.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>But wait&hellip;My tests fail now!</p>
<p>Why do they fail? Because of two things:</p>
<ul>
<li>Expressions don&rsquo;t rely on an interface but on <code>public abstract class Expression</code> : this means that our <code>_setterExpression.Body</code> will always fall on the last generic method.</li>
<li>and because the type PropertyExpression which I need implicitely here is defined as <code>internal class PropertyExpression : MemberExpression</code>&hellip;</li>
</ul>
<p>I don&rsquo;t want to criticize the design of the Linq Expressions namespace, because I can imagine this design has it&rsquo;s own very good reasons to be like that. But in my simple condition of developper and user of their framework I don&rsquo;t agree with the way I have to work with it.</p>
<p>That&rsquo;s why in this real life scenario, I finally end up with this code in order to make tests pass:</p>
<pre><code>public PropertySetterExpression(ConfigurationMappingsBase&lt;T&gt; source, Expression&lt;Func&lt;T, object&gt;&gt; setterExpression)
{
    _source = source;
    _setterExpression = setterExpression;
    _setter = InitializeSetter(_setterExpression.Body);
}

private Action&lt;T, object&gt; InitializeSetter(UnaryExpression expression)
{
    return InitializeSetter(expression.Operand as MemberExpression);
}

private Action&lt;T, object&gt; InitializeSetter(MemberExpression expression)
{
    if (expression.Member is PropertyInfo)
    {
        var pi = typeof(T).GetProperty(expression.Member.Name);
        return pi.GetValueSetter&lt;T&gt;();
    }
    throw new InvalidOperationException("Expression");
}

private Action&lt;T, object&gt; InitializeSetter(Expression expression)
{
    if (expression.NodeType == ExpressionType.Convert)
        return InitializeSetter((UnaryExpression) expression);
    if (expression.NodeType == ExpressionType.MemberAccess)
        return InitializeSetter((MemberExpression) expression);
    throw new InvalidOperationException("Expression");
}
</code></pre>
<p>Still better than my very first iteration but not as good as I want.</p>
<p>Any thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/rui/2012/07/18/solid-a-small-refactory-sequence-onconfart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some thoughts on ASP.NET ThreadPool Threads, asynchronous execution and TPL</title>
		<link>http://www.codedistillers.com/tja/2012/04/06/some-thoughts-on-asp-net-threadpool-threads-asynchronous-execution-and-tpl/</link>
		<comments>http://www.codedistillers.com/tja/2012/04/06/some-thoughts-on-asp-net-threadpool-threads-asynchronous-execution-and-tpl/#comments</comments>
		<pubDate>Fri, 06 Apr 2012 11:26:00 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Technical Posts]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[TPL]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=58</guid>
		<description><![CDATA[I’ve been always confused whenever you should or not implement asynchronous execution for “lengthy” operations when it comes to the ASP.NET platform. It has to be said that there is many factors that come into play. The way ASP.NET concurrent request are handled not only has changed over the different version of Framework .NET but [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been always confused whenever you should or not implement asynchronous execution for “lengthy” operations when it comes to the ASP.NET platform. It has to be said that there is many factors that come into play. The way ASP.NET concurrent request are handled not only has changed over the different version of Framework .NET but also you have to consider how ASP.NET deals with threads and ThreadPool in general. Since the very beginning I hear people saying to make usage of your own threads if you don’t want to starve the ThreadPool in ASP.NET process by queuing too many work items. It will prevent ASP.NET from processing further requests. Some confusion has been added with the recent release of TPL library and its usage inside the asynchronous pages/controllers/handlers in regards to the threads and ThreadPool consumption. All the more there is no clear guidance or rather no easy one to find. So let me now sum up all this when it comes to the latest .NET Framework (4/4.5).</p>
<h3>ASP.NET ThreadPool facts</h3>
<ul>
<li>ASP.NET uses threads from a common language runtime (CLR) thread pool to process requests. As long as there are threads available in the thread pool, ASP.NET has no trouble dispatching incoming requests.</li>
<li>Async delegates use the threads from ThreadPool.</li>
</ul>
<h3>When you should start thinking about implementing asynchronous execution ?</h3>
<ul>
<li>When your application performs relatively lengthy I/O operations (database queries, Web service calls, and other I/O operations).</li>
<li>If you want to do I/O work, then you should be using an I/O thread (I/O Completion Port) and specifically you should be using the async callbacks supported by whatever library class you&#8217;re using. Theirs names start with the words Begin and End.</li>
<li>If requests are computationally cheap to process, then parallelism is probably an unnecessary overhead.</li>
<li>If the incoming request rate is high, then adding more parallelism will likely yield few benefits and could actually decrease performance, since the incoming rate of work may be high enough to keep the CPUs busy.</li>
</ul>
<h3>Should I create new Threads ?</h3>
<ul>
<li>Avoid creating new threads like you would avoid the plague.</li>
<li>If you are actually queuing enough work items to prevent ASP.NET from processing further requests, then you should be starving the thread pool! If you are running literally hundreds of CPU-intensive operations at the same time, what good would it do to have another worker thread to serve an ASP.NET request, when the machine is already overloaded.</li>
</ul>
<h3>What about the TPL and async await? Does it solve my problems ?</h3>
<ul>
<li>TPL can adapt to use available resources within a process. If the server is already loaded, the TPL can use as little as one worker and make forward progress. If the server is mostly free, they can grow to use as many workers as the ThreadPool can spare.</li>
<li>Tasks use threadpool threads to execute.</li>
<li>When async/await will not consume an additional ThreadPool thread ? Only in the case you are using BCL Async methods. that uses an IOCP thread to execute the IO bound operation.</li>
</ul>
<p>If you are trying to <strong>async execute some sync code or your own library code</strong>, that code will probably <strong>use an additional ThreadPool thread</strong> unless you explicitly use the IOCP ThreadPool or your own ThreadPool. But as far as I know you can&#8217;t chose whatever you want to use a IOCP thread, and making correct implementation of the ThreadPool is not worth the effort. I doubt someone does a better one that already exists.</p>
<p>I scratched only the surface but if you have more suggestions don’t hesitate to leave me a comment.</p>
<p>Thomas</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/tja/2012/04/06/some-thoughts-on-asp-net-threadpool-threads-asynchronous-execution-and-tpl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About Asp.Net Web Stack</title>
		<link>http://www.codedistillers.com/rui/2012/04/03/about-asp-net-web-stack/</link>
		<comments>http://www.codedistillers.com/rui/2012/04/03/about-asp-net-web-stack/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 16:54:54 +0000</pubDate>
		<dc:creator>rui</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[aspnetmvc]]></category>
		<category><![CDATA[OSS]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/?p=53</guid>
		<description><![CDATA[A few days ago, Microsoft released its ASP.NET Web Stack (of Love as called by Hanselman) to OSS. Good news? Bad news? I don’t know… I am still not convinced by the capacity of Microsoft to produce with a real OSS community a really pen source project. This time, and it’s quite new for them, [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, Microsoft released its ASP.NET Web Stack (of Love as called by Hanselman) to OSS. </p>
<h2>Good news? Bad news?</h2>
<p>I don’t know… I am still not convinced by the capacity of Microsoft to produce with a real OSS community a really pen source project. This time, and it’s quite new for them, they claims to accept pull requests from community. </p>
<p>I am not sure that it will make a big difference with the past, but I may be wrong (and I hope so!)</p>
<p>Just before continuing, I am not here to say that all this asp.net web stack and oss stories are a mess! I am still a big fan of the stack and I am only writing about some thoughts and experiments. </p>
<h2>So, I git clone!</h2>
<p>Obviously we can spend hours discussing philosophy about Microsoft misconception on open source, but to begin, the better way is to try it.</p>
<p>I don’t know if it is on purpose to be on the “OSS Move”, but CodePlex support since a few time Git. It’s another good news!</p>
<p>Oh wait…Perhaps we missed something? </p>
<ol>
<li>If you’re true open source now, why not choosing a neutral platform –like GitHub – instead of a Microsoft source showcase without any soul like Codeplex?</li>
<li>Codeplex supporting git is good, but,&#160; after svn or mercurial some years ago because it was the trend of the moment, doesn’t it undermines the solutions based on TFS a little bit? Or finally they are now convinced that TFS is not good for distributed open source project? Must probably, it is to let the platform die silently and empower in the future a platform based on the Tfs Cloud solution – which can be most intelligent solution.</li>
</ol>
<p>&#160;</p>
<p>So I can clone without installing the 300Mo iso of TFS explorer and that’s nice <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Clignement d&#39;œil" src="http://www.codedistillers.com/wp-content/uploads/2012/04/wlEmoticon-winkingsmile.png" /></p>
<pre class="brush: shell;">git clone <a href="https://git01.codeplex.com/aspnetwebstack.git">https://git01.codeplex.com/aspnetwebstack.git</a></pre>
<p>&#160;</p>
<p>That’s pretty quick (due to git compression, yeah!) and I can navigate the sources now. </p>
<h2>Build It</h2>
<p>I don’t know if everyone is more serious than me but one thing I always do after getting some sources, is to type “build” in the shell and see what happened, don’t you? It’s just to see if it can work immediately on a simple way. Let’s call it a “Download and Run” pattern.</p>
<p>I was a little bit disappointed with all screaming in red…And I forgot to say that, like most people, I explicitly forgot to read the recommendations and “README” you should read after downloading something.</p>
<p>So that’s it. It’s not clear on the project home page, but if you go to <a href="http://aspnetwebstack.codeplex.com/documentation" target="_blank">Documentation</a>, you have most of the solutions to your problems:</p>
<ol>
<li>Download <a href="http://www.codeplex.com/Download?ProjectName=aspnetwebstack&amp;DownloadId=360565">SkipStrongNames</a>, and unzip it. From an <strong>elevated command prompt</strong>, run “skipstrongnames -e&quot; to allow you to run unit tests against the delay-signed binaries. </li>
<li><strong>Don’t try</strong> to open directly the Runtime.sln&#160; and “enable nuget restore” before launching a first build command. I will run a mess when you try to launch build.cmd later…</li>
</ol>
<p>&#160;</p>
<p>Additional Tip: You may need to manually add a specific Microsoft nuget development feed for some packages not yet officially distributed: In Visual Studio, open Tools/Library Package Manager/Settings Then in Packages Sources add new with this url:</p>
<pre class="brush: js;">http://www.myget.org/F/f05dce941ae4485090b04586209c8b08/</pre>
<p>&#160;</p>
<p>So, after applying SkipStrongNames (did I already mention that I hate StrongNames?), just restore your nuget packages:</p>
<pre class="brush: shell;">./build.cmd RestorePackages</pre>
<p>&#160;</p>
<p>Then try to build it (without restore).</p>
<p>I said hope, because depending on your current configuration and state it may work or not:</p>
<ul>
<li> Having .Net 4.5 and/or aspnet mvc4 beta installed may cause troubles</li>
<li>Having some data components may cause troubles (Maybe Sql 2012 is one…)</li>
</ul>
<p>&#160;</p>
<p>I finally get it working after removing .Net 4.5/mvc4 and removing the Microsoft.Web.Http.Data.Test project…</p>
<p>But, after uninstalling these components, msbuild 4 disappear too and mvc3 template projects just not work anymore.</p>
<p>&#160;</p>
<h2>A few words more</h2>
<p>It’s is interesting to have the real sources of all the web stack but use it with caution. </p>
<p>It’s usually hard to compose with some beta versions from Microsoft that are not compatible with other tools but it’s also the case with these sources. </p>
<p>It’s far to be an independent project, and I can understand why it’s not, but it’s quite difficult to exploit and contribute to sources with these inter-dependencies. </p>
<p>I just hope that it will open some minds and bring real innovation. In the other hand, I hope it will help people usually using basically Microsoft products to have a new point of view on new ways of working.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/rui/2012/04/03/about-asp-net-web-stack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ALT.NET Paris : My talk on DI patterns and anti-patterns</title>
		<link>http://www.codedistillers.com/tja/2012/03/11/alt-net-paris-my-talk-on-di-patterns-and-anti-patterns/</link>
		<comments>http://www.codedistillers.com/tja/2012/03/11/alt-net-paris-my-talk-on-di-patterns-and-anti-patterns/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 23:47:00 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[ALT.NET]]></category>
		<category><![CDATA[DI]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/tja/2012/03/11/alt-net-paris-my-talk-on-di-patterns-and-anti-patterns/</guid>
		<description><![CDATA[I’ll be speaking with Olivier Spinelli about IoC/DI patterns and anti-patterns at the next meeting of Paris ALT.NET group on 15th of mars 2012. Form more information please look here (french) : http://www.altnetfr.org/2012/01/22/alt-net-presentation-ioc-patterns-et-anti-patterns/#comments. Thomas.Dispose(); CodeDistillers.WaitFormPendingFinalizers();]]></description>
			<content:encoded><![CDATA[<p>I’ll be speaking with Olivier Spinelli about IoC/DI patterns and anti-patterns at the next meeting of Paris ALT.NET group on 15th of mars 2012. Form more information please look here (french) : <a title="http://www.altnetfr.org/2012/01/22/alt-net-presentation-ioc-patterns-et-anti-patterns/#comments" href="http://www.altnetfr.org/2012/01/22/alt-net-presentation-ioc-patterns-et-anti-patterns/#comments">http://www.altnetfr.org/2012/01/22/alt-net-presentation-ioc-patterns-et-anti-patterns/#comments</a>.</p>
<p>Thomas.Dispose();</p>
<p>CodeDistillers.WaitFormPendingFinalizers();</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/tja/2012/03/11/alt-net-paris-my-talk-on-di-patterns-and-anti-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Api (beta) and Castle.Windsor&#8230;without IDependencyResolver ?</title>
		<link>http://www.codedistillers.com/tja/2012/03/11/web-api-beta-and-castle-windsorwithout-idependencyresolver/</link>
		<comments>http://www.codedistillers.com/tja/2012/03/11/web-api-beta-and-castle-windsorwithout-idependencyresolver/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 23:23:00 +0000</pubDate>
		<dc:creator>Thomas</dc:creator>
				<category><![CDATA[Technical Posts]]></category>
		<category><![CDATA[ASP.NET Web Api]]></category>
		<category><![CDATA[Castle.Windsor]]></category>
		<category><![CDATA[DI]]></category>
		<category><![CDATA[IoC]]></category>

		<guid isPermaLink="false">http://www.codedistillers.com/tja/2012/03/11/web-api-beta-and-castle-windsorwithout-idependencyresolver/</guid>
		<description><![CDATA[I’ve been reading through several blog post about how people configure DI support in the new ASP.NET Web Api. For example you can read about it here : Official “Using the Web API Dependency Resolver” “Autofac ASP.NET Web API (Beta) Integration“ “Web Api and Ninject” What stands out is that every implementation relays on System.Web.Http.Services.IDependencyResolver [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been reading through several blog post about how people configure DI support in the new <a href="http://www.asp.net/web-api" target="_blank">ASP.NET Web Api</a>. For example you can read about it here : </p>
<ul>
<li>Official “<a href="http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver" target="_blank">Using the Web API Dependency Resolver</a>”</li>
<li>“<a href="http://alexmg.com/post/2012/03/08/Autofac-ASPNET-Web-API-(Beta)-Integration.aspx" target="_blank">Autofac ASP.NET Web API (Beta) Integration</a>“</li>
<li>“<a href="http://wildermuth.com/2012/2/26/WebAPI_and_Ninject" target="_blank">Web Api and Ninject</a>”</li>
</ul>
<p>What stands out is that every implementation relays on <font face="Courier New"><strong>System.Web.Http.Services.IDependencyResolver</strong></font> interface which is similar to the one introduced in the ASP.NET MVC 3 and which lives in the <font face="Courier New"><strong>System.Web.Mvc</strong></font> namespace to avoid confusion. Let’s look at it’s implementation details :</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IDependencyResolver</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">object</span> GetService(System.Type serviceType);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     IEnumerable&lt;<span style="color: #0000ff">object</span>&gt; GetServices(System.Type serviceType);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Since it was introduced in MVC 3 I’ve never used it because of it’s lack of “Release” method and the fact that there is now way cleaning-up resolved services from you DI container. If it’s not a problem for all DI containers, it is certainly a problem for Castle.Windsor which tracks resolved components. <a href="http://mikehadlow.blogspot.com" target="_blank">Mike Hadlow</a> already spotted it was a problem and wrote a blog post “<a href="http://mikehadlow.blogspot.com/2011/02/mvc-30-idependencyresolver-interface-is.html" target="_blank">The MVC 3.0 IDependencyResolver interface is broken. Don’t use it with Windsor.</a>” I think that this problem still remains with a WebApi <font face="Courier New"><strong>IDependencyResolver</strong></font> interface and that’s why I decided to not use it. But will I manage to do it ?</p>
<h1>Self Hosting</h1>
<p>My current WebApi project is using self hosting feature and for the moment I won’t be interested in IIS hosting. After all, there should not be significant differences between two hosting options on adding IoC container support. We will check it after.</p>
<p>Given that in ASP.NET MVC 3 we weren’t compelled to implement <font face="Courier New"><strong>IDependencyResolver</strong></font> at all I started to figure out what other hooks WebApi offers in order to set up my <a href="http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx" target="_blank">Composition Root</a>. After few minutes of inspecting WebApi’s API, I found <font face="Courier New"><strong>IHttpControllerFactory</strong></font> in the <font face="Courier New"><strong>System.Web.Http.Dispatcher</strong></font> namespace which seems to me like a viable seam for connecting my own implementation. This interface is quite similar to the one from the <font face="Courier New">System.Web.Mvc</font> namespace and is all what I need.</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IHttpControllerFactory</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     IHttpController CreateController(HttpControllerContext controllerContext, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>                                                         <span style="color: #0000ff">string</span> controllerName);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     <span style="color: #0000ff">void</span> ReleaseController(IHttpController controller);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>As you noticed, there is “Create” and “Release” controller methods which allows me to use it with Castle.Windsor. Let’s look at it :</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> WindsorHttpControllerFactory : IHttpControllerFactory</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> IWindsorContainer _windsorContainer;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     <span style="color: #0000ff">public</span> WindsorHttpControllerFactory(IWindsorContainer windsorContainer)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>         <span style="color: #0000ff">if</span> (windsorContainer == <span style="color: #0000ff">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>             <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentNullException(<span style="color: #006080">&quot;windsorContainer&quot;</span>, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>                             <span style="color: #006080">&quot;The instance of the container cannot be null.&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>         _windsorContainer = windsorContainer;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>     <span style="color: #0000ff">public</span> IHttpController CreateController(</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>                                     HttpControllerContext controllerContext, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>                                     <span style="color: #0000ff">string</span> controllerName)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>         var controllerFullName = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}.{1}{2}&quot;</span>, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>                     <span style="color: #0000ff">typeof</span>(OrderController).Namespace, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>                     controllerName, ControllerSuffix);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>         var controllerType = Type.GetType(controllerFullName);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span>         <span style="color: #0000ff">return</span> _windsorContainer.Resolve(controllerType) as IHttpController;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24">  24:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25">  25:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26">  26:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> ReleaseController(IHttpController controller)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27">  27:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28">  28:</span>         var disposableController = controller <span style="color: #0000ff">as</span> IDisposable;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29">  29:</span>         <span style="color: #0000ff">if</span> (disposableController != <span style="color: #0000ff">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30">  30:</span>             disposableController.Dispose();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum31">  31:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum32">  32:</span>         _windsorContainer.Release(controller);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum33">  33:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum34">  34:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Straightforward implementation that doesn’t need any comments. Next step is to register it in the WebApi framework.</p>
<h2>First Fail : Registration</h2>
<p>I really should start from there… Looking into the WebApi’s API I can’t really find where to register my own implementation into the framework. It seems that there is nothing similar to <font face="Courier New">ControllerBuilder.Current.SetControllerFactory</font>. My current startup code is like this :</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> var config = <span style="color: #0000ff">new</span> HttpSelfHostConfiguration(<span style="color: #006080">&quot;http://localhost:6666&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> config.Routes.MapHttpRoute(<span style="color: #006080">&quot;defualt&quot;</span>, <span style="color: #006080">&quot;{controller}/{id}&quot;</span>, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>                                 <span style="color: #0000ff">new</span> {id = RouteParameter.Optional});</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span> var server = <span style="color: #0000ff">new</span> HttpSelfHostServer(config);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span> server.OpenAsync().Wait();</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Once again, standard initialization. But there is nothing on the <font face="Courier New">HttpSelfHostConfiguration</font> class that allows defining your own <font face="Courier New"><strong>IHttpControllerFactory</strong></font> implementation. The only thing I can see is <font face="Courier New">HttpSelfHostConfiguration.ServiceResolver.SetResolver</font> methods with it’s overrides. It seems that there is no way to avoid implementing <font face="Courier New"><strong>IDependencyResolver</strong></font> interface. So let’s do it.</p>
<h3>Rolling out my own Dependency Resolver</h3>
<p>As my unique solution is to implement my own <font face="Courier New"><strong>IDependencyResolver</strong></font> so let’s do it :</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> WindsorDependencyResolver : IDependencyResolver</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> WindsorContainer _windsorContainer;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>     <span style="color: #0000ff">public</span> WindsorDependencyResolver(WindsorContainer windsorContainer)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>         <span style="color: #0000ff">if</span> (windsorContainer == <span style="color: #0000ff">null</span>)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>             <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> ArgumentNullException(<span style="color: #006080">&quot;windsorContainer&quot;</span>, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>                         <span style="color: #006080">&quot;The instance of the container cannot be null.&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>         _windsorContainer = windsorContainer;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> GetService(Type serviceType)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>         <span style="color: #0000ff">try</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>             <span style="color: #0000ff">return</span> _windsorContainer.Resolve(serviceType);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>         <span style="color: #0000ff">catch</span> (ComponentNotFoundException)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22">  22:</span>             <span style="color: #0000ff">return</span> <span style="color: #0000ff">null</span>;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23">  23:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24">  24:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum25">  25:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum26">  26:</span>     <span style="color: #0000ff">public</span> IEnumerable&lt;<span style="color: #0000ff">object</span>&gt; GetServices(Type serviceType)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum27">  27:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum28">  28:</span>         <span style="color: #0000ff">try</span></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum29">  29:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum30">  30:</span>             <span style="color: #0000ff">return</span> _windsorContainer.ResolveAll(serviceType).Cast&lt;<span style="color: #0000ff">object</span>&gt;();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum31">  31:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum32">  32:</span>         <span style="color: #0000ff">catch</span> (ComponentNotFoundException)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum33">  33:</span>         {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum34">  34:</span>             <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">object</span>&gt;();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum35">  35:</span>         }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum36">  36:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum37">  37:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Then we have to register it as follows :</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Main(<span style="color: #0000ff">string</span>[] args)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     var container = <span style="color: #0000ff">new</span> WindsorContainer();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     container.Install(FromAssembly.This());</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>     var config = <span style="color: #0000ff">new</span> HttpSelfHostConfiguration(<span style="color: #006080">&quot;http://localhost:6666&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     <strong>config.ServiceResolver.SetResolver</strong></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>                         <strong>(<span style="color: #0000ff">new</span> WindsorDependencyResolver(container));</strong></pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     config.Routes.MapHttpRoute(<span style="color: #006080">&quot;defualt&quot;</span>, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>                 <span style="color: #006080">&quot;{controller}/{id}&quot;</span>, <span style="color: #0000ff">new</span> { id = RouteParameter.Optional });</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>     </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     <span style="color: #0000ff">using</span> (var server = <span style="color: #0000ff">new</span> HttpSelfHostServer(config))</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>         server.OpenAsync().Wait();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span>         Console.WriteLine(<span style="color: #006080">&quot;The server is running.&quot;</span>);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17">  17:</span>         Console.ReadLine();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18">  18:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19">  19:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20">  20:</span>     container.Dispose();</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21">  21:</span> }</pre>
<p><!--CRLF--></div>
</div>
<div>&#160;</div>
<div>This is not sufficient because of the problem described at the beginning of this post (the lack of the “Release” method and thus being unable to release components resolved with Castle.Windsor). The next step is to figure out how to register our implementation of <font face="Courier New"><strong>IHttpControllerFactory</strong></font>. The good news is that that framework WebApi calls every time to our implementation of <font face="Courier New">IDependencyResolver</font> in the hope that it could find a service for every seam that is try to resolve. One of that seams is <font face="Courier New"><strong>IHttpControllerFactory</strong></font> so it easy to register our own implementation with Castle.Windsor :</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ControllerFactoryInstaller : IWindsorInstaller</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Install(IWindsorContainer container, IConfigurationStore store)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>         container.Register(</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>             Component.For&lt;IHttpControllerFactory&gt;().Instance(</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>                 <span style="color: #0000ff">new</span> WindsorHttpControllerFactory(container)));</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>     }</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span> }</pre>
<p><!--CRLF--></div>
</div>
<div>&#160;</div>
<p>Note, that the default liftetime when unspecified is Singleton.</p>
<p>We’re ready to test.</p>
<h3>Second Fail : Testing in Fiddler</h3>
<p>To my surprise, when calling my service I end up with the following error (sorry for the French) : </p>
<p><font face="Courier New"><em>{&quot;ExceptionType&quot;:&quot;System.NullReferenceException&quot;,&quot;Message&quot;:&quot;La référence d&#8217;objet n&#8217;est pas définie à une instance d&#8217;un objet.&quot;,&quot;StackTrace&quot;:&quot;&#160;&#160; à System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\u000d\u000a&#160;&#160; à System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)\u000d\u000a&#160;&#160; à System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)&quot;}</em></font></p>
<p>For me it brakes the <a href="http://en.wikipedia.org/wiki/Principle_of_least_astonishment" target="_blank">POLA</a>. After wandering on Internet I didn’t find anything helpful. I decompiled some WebApi code sources, debugged once again and found that the instance of <font face="Courier New">HttpControllerContext</font> passed to my controller factory was a bit strange. In fact <font face="Courier New">ControllerDescriptor</font> and <font face="Courier New">Controller</font> properties was not assigned. By trial and error I ended up modifying my implementation like this :</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1">   1:</span> <span style="color: #0000ff">public</span> IHttpController CreateController(HttpControllerContext controllerContext, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2">   2:</span>                                                             <span style="color: #0000ff">string</span> controllerName)</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3">   3:</span> {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4">   4:</span>     var controllerFullName = <span style="color: #0000ff">string</span>.Format(<span style="color: #006080">&quot;{0}.{1}{2}&quot;</span>, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5">   5:</span>                                                 <span style="color: #0000ff">typeof</span>(OrderController).Namespace, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6">   6:</span>                                                 controllerName, ControllerSuffix);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7">   7:</span>     var controllerType = Type.GetType(controllerFullName);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8">   8:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9">   9:</span>     controllerContext.ControllerDescriptor = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10">  10:</span>                 <span style="color: #0000ff">new</span> HttpControllerDescriptor(controllerContext.Configuration, </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11">  11:</span>                                                     controllerName, controllerType);</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12">  12:</span>     controllerContext.Controller = </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13">  13:</span>                     _windsorContainer.Resolve(controllerType) <span style="color: #0000ff">as</span> IHttpController;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14">  14:</span>&#160; </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15">  15:</span>     <span style="color: #0000ff">return</span> controllerContext.Controller;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16">  16:</span> }</pre>
<p><!--CRLF--></div>
</div>
<p>&#160;</p>
<p>Now everything works as expected. It’s a bit weird as these properties seem to be optional from the point of view of the API, or at least they should be provided with the instance of <font face="Courier New">HttpControllerContext</font>.</p>
<h2>In Closing</h2>
<p>As you see, there is no way to get rid of <font face="Courier New">IDependencyResolver</font> in the WebApi compared to MVC. It’s a pity because it puts another burden on the developer to implement an interface that doesn’t act as a composition root. In fact our composition root is resolved from the implementation of <font face="Courier New">IDependencyResolver</font> so it’s a bit confusing. It’s understandable from the point of view of ASP.NET team which wanted to make <font face="Courier New">IDependencyResolver</font> a central piece of IoC support in the WebApi framework but for me it presents some design flaws as the API is not clear enough which seams should be used and how exactly implement them.</p>
<p>In the next post I’ll do the test implementing it in IIS hosting environment.</p>
<p>&#160;</p>
<p>Thomas.Dispose();</p>
<p>CodeDistillers.WaitForPendingFinalizers();</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codedistillers.com/tja/2012/03/11/web-api-beta-and-castle-windsorwithout-idependencyresolver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
