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

<channel>
	<title>igorbrejc.net &#187; C#</title>
	<atom:link href="http://igorbrejc.net/category/development/c/feed" rel="self" type="application/rss+xml" />
	<link>http://igorbrejc.net</link>
	<description>Just another developer's weblog</description>
	<lastBuildDate>Sun, 12 Feb 2012 06:47:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Maperitive Build 1108</title>
		<link>http://igorbrejc.net/development/c/maperitive-build-1108</link>
		<comments>http://igorbrejc.net/development/c/maperitive-build-1108#comments</comments>
		<pubDate>Thu, 20 Jan 2011 21:12:29 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Maperitive]]></category>
		<category><![CDATA[OpenStreetMap]]></category>
		<category><![CDATA[parallel.extensions]]></category>
		<category><![CDATA[PBF]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1369</guid>
		<description><![CDATA[photo credit: Omar Eduardo My previous post about PBF reading successes was written way too prematurely. It turned out my PBF reading code had some serious bugs which made reading look much faster than it actually was (one of the reasons was that I neglected to read OSM node keys/values when written in PBF dense [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/22406241@N00/127707517/" title="Supporting the Liberty (fries?)" target="_blank"><img src="http://farm1.static.flickr.com/43/127707517_1ce118b77a.jpg" alt="Supporting the Liberty (fries?)" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-nc-nd/2.0/" title="Attribution-NonCommercial-NoDerivs License" target="_blank"><img src="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/22406241@N00/127707517/" title="Omar Eduardo" target="_blank">Omar Eduardo</a></small></p>

<p><a href="http://igorbrejc.net/development/maperitive-reading-osm-pbf-files">My previous post</a> about PBF reading successes was written way too prematurely. It turned out my PBF reading code had some serious bugs which made reading look much faster than it actually was (one of the reasons was that I neglected to read OSM node keys/values when written in <a href="http://wiki.openstreetmap.org/wiki/PBF_Format#Nodes">PBF dense node format</a>).</p>

<p>I’ve subsequently written some extensive tests, comparing OSM database contents from XML and PBF file of the same area (thanks Geofabrik) on an object by object basis, so I’m now 95% sure the PBF code works OK. Performance-wise the (final?) results are much less glamorous than it looked initially: PBF reading <strong>is “only” 2.5 times faster than reading OSM.bz2 files, while in memory consumption terms, they are pretty much the same</strong>. I curious what other OSM software like osmosis has to say about these results.</p>

<p>I had hoped I could speed the PBF reading by spreading the work on several processor cores. What I did is to use <a href="http://en.wikipedia.org/wiki/Parallel_Extensions">Microsoft’s Parallel Extensions library</a> to separate the fetching of PBF file blocks from the actual parsing of them into two (or more) cores. This resulted in only about 10% increase of the overall speed (tested on my two-core machine, so on more cores the result could be better).</p>

<p>It actually proved pretty hard to do a decent job of separating work in some balanced fashion. Since the file reading is sequential, this can only be done by one thread/core, so you want to put as little other work to that core as possible. As soon as file block bytes are fetched from the file, they are delegated to another core to parse it (in terms of protocol buffers) and then extract OSM objects from it. The problem is that you don’t want to enqueue too many file blocks at the same time, since this takes up valuable memory (which is already filled with extracted OSM objects). So I ended up using a <a href="http://msdn.microsoft.com/en-us/library/dd267312.aspx">blocking queue</a>, which means the main thread (which reads the file) will wait until at least one core is available before filling the queue with another file block.</p>

<p>I’ve also tried micro-management strategy – using multiple cores to extract individual OSM objects, but this only really works for ways and relations. Current PBF extracts use dense nodes format, which is <a href="http://en.wikipedia.org/wiki/Delta_encoding">delta-encoded</a> and thus forces you to read things sequentially on a single thread of execution. I guess this is the price of having a format that wants to satisfy two different (and inherently conflicting) goals: less space and less CPU.</p>

<p>I’m fairly new to Parallel Extensions and there are probably better ways of handling this, but I’ll leave it for the future.</p>

<p>Anyway, a new Maperitive release is out, grab it from <a href="http://maperitive.net/download/">the usual place</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/maperitive-build-1108/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:thumbnail url="http://farm1.static.flickr.com/43/127707517_1ce118b77a.jpg" />
		<media:content url="http://farm1.static.flickr.com/43/127707517_1ce118b77a.jpg" medium="image">
			<media:title type="html">Supporting the Liberty (fries?)</media:title>
		</media:content>
		<media:content url="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" medium="image">
			<media:title type="html">Creative Commons License</media:title>
		</media:content>
	</item>
		<item>
		<title>Web Testing &amp; Gallio: A Little Helpful Trick</title>
		<link>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick</link>
		<comments>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick#comments</comments>
		<pubDate>Mon, 18 Oct 2010 05:59:08 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1290</guid>
		<description><![CDATA[When doing automatic testing of Web apps using unit testing frameworks, it can be a pain in the butt to pinpoint the proper HTML element. A lot of times tests will fail because you used a wrong locator, but since the browser will automatically close after the test, you don’t have an access to the [...]]]></description>
			<content:encoded><![CDATA[<p>When doing automatic testing of Web apps using unit testing frameworks, it can be a pain in the butt to pinpoint the proper HTML element. A lot of times tests will fail because you used a wrong locator, but since the browser will automatically close after the test, you don’t have an access to the HTML code of the page to look at what’s actually there.</p>

<p>Fortunately Gallio provides a class called <strong>TestContext</strong> which contains the current information about the running test and which you can use to determine if the latest test is successful or not. This can then be used to run your custom handling code during the test teardown:</p>

<p>
<pre class="brush: csharp; title: ; notranslate">
        [TearDown]
        protected virtual void Teardown()
        {
            if (TestContext.CurrentContext.Outcome.Status == TestStatus.Failed)
            {
                using (TestLog.BeginSection(&quot;Failed web page HTML&quot;))
                    TestLog.Write(WebDriver.PageSource);
            }
        }
</pre></p>

<p>In the above snippet, we record the current Web page’s HTML code into Gallio’s log (the <strong>TestLog</strong> class). To avoid spamming the log, we do this for failed tests only. </p>

<p>Gallio provides a powerful framework which I think is very much underused, mostly because the documentation is not very detailed (to say the least).</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
	</item>
		<item>
		<title>Windsor Castle: Strange Resolving Behavior</title>
		<link>http://igorbrejc.net/development/c/windsor-castle-strange-resolving-behavior</link>
		<comments>http://igorbrejc.net/development/c/windsor-castle-strange-resolving-behavior#comments</comments>
		<pubDate>Tue, 24 Aug 2010 05:43:38 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Windsor Castle]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1250</guid>
		<description><![CDATA[A user reported a bug in Maperitive – it throws Castle.MicroKernel.Resolvers.DependencyResolverException: Could not resolve non-optional dependency for &#8216;Karta.DataSources.OsmFileMapDataSource&#8217; (Karta.DataSources.OsmFileMapDataSource). Parameter &#8216;fileName&#8217; type &#8216;System.String&#8217; I tried to reproduce this behavior using a simple unit test, but I couldn’t, so I’m posting the actual code. This is where the exception occurs: And this is how OsmFileMapDataSource constructors [...]]]></description>
			<content:encoded><![CDATA[<p>A user reported a bug in Maperitive – it throws </p>

<blockquote>   <p>Castle.MicroKernel.Resolvers.DependencyResolverException: Could not resolve non-optional dependency for &#8216;Karta.DataSources.OsmFileMapDataSource&#8217; (Karta.DataSources.OsmFileMapDataSource). Parameter &#8216;fileName&#8217; type &#8216;System.String&#8217;</p> </blockquote>

<p><font color="#666666">I tried to reproduce this behavior using a simple unit test, but I couldn’t, so I’m posting the actual code. This is where the exception occurs:</font></p>

<p>
<pre class="brush: csharp; title: ; notranslate">return windsorContainer.Resolve&lt;OsmFileMapDataSource&gt;();</pre></p>

<p><font color="#666666">And this is how <strong>OsmFileMapDataSource</strong> constructors look like:</font></p>

<p><pre class="brush: csharp; title: ; notranslate">
        public OsmFileMapDataSource(
            string fileName,
            IFileSystem fileSystem,
            IMapDataLayerFactory layerFactory)
        {
            ...
        }

        public OsmFileMapDataSource(IMapDataLayerFactory layerFactory)
        {
           ...
        }
</pre></p>

<p><font color="#666666">Needless to say, both <strong>IFileSystem</strong> and <strong>IMapDataLayerFactory</strong> are registered in the container (<strong>IMapDataLayerFactory</strong> is registered as a typed factory, by the way). <strong>OsmFileMapDataSource</strong> is also registered as an implementation of itself. And I’m using version 2.1.0.6655 of the library.</font></p>

<p><font color="#666666">What’s strange about this is that <strong>if I move the second constructor in front of the first one, the component is resolved without problems</strong>. I’m not sure if this is intended behavior, but I doubt the order of constructors should be a determining factor on how components are resolved.</font></p>

<p><font color="#666666">But as I said, I couldn’t reproduce this behavior using a simplified test code, so I guess I should start debugging it instead.</font></p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/windsor-castle-strange-resolving-behavior/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
	</item>
		<item>
		<title>Maperitive: Enhanced Usability &amp; Scripting Support</title>
		<link>http://igorbrejc.net/development/c/maperitive-enhanced-usability-scripting-support</link>
		<comments>http://igorbrejc.net/development/c/maperitive-enhanced-usability-scripting-support#comments</comments>
		<pubDate>Fri, 06 Aug 2010 19:10:43 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Maperitive]]></category>
		<category><![CDATA[OpenStreetMap]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/c/maperitive-enhanced-usability-scripting-support</guid>
		<description><![CDATA[For the last week or so I’ve been busting my fingers with one of the harder things to implement in a desktop GUI: application responsiveness when executing longer-running tasks. By longer-running I mean something that takes more than a couple of seconds. Simple desktop applications tend to run everything synchronously: when the user presses a [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Maperitive running scripts" href="http://www.flickr.com/photos/28786233@N03/4866209357/"><img border="0" alt="Maperitive running scripts" src="http://farm5.static.flickr.com/4122/4866209357_b95edd0f2e_b.jpg" width="659" height="453" /></a></p>

<p>For the last week or so I’ve been busting my fingers with one of the harder things to implement in a desktop GUI: application responsiveness when executing longer-running tasks. By longer-running I mean something that takes more than a couple of seconds.</p>

<p>Simple desktop applications tend to run everything synchronously: when the user presses a button, the action gets run. After the action finishes, the control is given back to the user. Simple, but totally crappy. The problem is that the action gets run on the same thread that services the GUI, so until the action finishes, the application will not be able even to refresh itself or respond in any meaningful way to user clicks or key presses. And since there is no refresh, you cannot show any progress indicators to the user. I know I wouldn’t want to wait half an hour for something to finish without some reassurance that the application is still alive and not waiting for the electricity to run out.</p>

<p>Maperitive already had a lot of responsiveness code implemented, but it was still an “under the construction” design. The additional complication was the fact I want Maperitive to have a good script runner and scripts can take a very long time (downloading OSM data, generating tiles etc.). After a lot of trials and errors I finally managed to implement the whole thing in a consistent package. And believe me when I say it was not easy.</p>

<p>So what is new:</p>

<ul>   <li>When running scripts (or longer tasks), Maperitive draws an indicator on the map (see the screenshot above) and launches a “sort of <a href="http://en.wikipedia.org/wiki/Modal_window">modal</a>” mode – most of GUI controls are disabled so the script doesn’t get confused by some inadvertent user action. However, the application is still responsive: you can view the progress of the script in the command log.</li>    <li>Aborting scripts: as the indicator says, you can press the <a href="http://en.wikipedia.org/wiki/Esc_key">escape key</a> to abort the script. If you prefer torturing your mouse instead of your keyboard, there’s an “Abort task” button in the bottom right corner which does the same thing.</li> </ul>

<p>Not all of running tasks have been switched to the new system. Loading OSM files is one example of a task that will still block the GUI, but I will gradually improve these things.</p>

<p>You can download the latest release at <a href="http://maperitive.net/download/">http://maperitive.net/download/</a></p>

<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/maperitive-enhanced-usability-scripting-support/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://farm5.static.flickr.com/4122/4866209357_b95edd0f2e_b.jpg" />
		<media:content url="http://farm5.static.flickr.com/4122/4866209357_b95edd0f2e_b.jpg" medium="image">
			<media:title type="html">Maperitive running scripts</media:title>
		</media:content>
	</item>
		<item>
		<title>Uri Class Cheat Sheet</title>
		<link>http://igorbrejc.net/development/c/uri-class-cheat-sheet</link>
		<comments>http://igorbrejc.net/development/c/uri-class-cheat-sheet#comments</comments>
		<pubDate>Mon, 12 Jul 2010 07:15:57 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/c/uri-class-cheat-sheet</guid>
		<description><![CDATA[Another reference post, this time covering usage of .NET Uri class. Example URL: http://somewhere.else.com:9999/service/packages?page=2#fragment The table below contains values for various properties of Uri for that example URL: AbsolutePath /service/packages AbsoluteUri http://somewhere.else.com:9999/service/packages?page=2#fragment Authority somewhere.else.com:9999 DnsSafeHost somewhere.else.com Fragment #fragment Host somewhere.else.com HostNameType Dns IsAbsoluteUri true IsDefaultPort false IsFile false IsLoopback false IsUnc false LocalPath /service/packages OriginalString [...]]]></description>
			<content:encoded><![CDATA[<p>Another reference post, this time covering usage of .NET <a href="http://msdn.microsoft.com/en-us/library/system.uri.aspx" target="_blank">Uri</a> class. </p>

<p>Example URL: http://somewhere.else.com:9999/service/packages?page=2#fragment</p>

<p>The table below contains values for various properties of Uri for that example URL:</p>

<table border="1" cellspacing="0" cellpadding="5" width="622"><tbody>     <tr>       <td valign="top" width="158">AbsolutePath</td>        <td valign="top" width="462">/service/packages</td>     </tr>      <tr>       <td valign="top" width="158">AbsoluteUri</td>        <td valign="top" width="462">http://somewhere.else.com:9999/service/packages?page=2#fragment</td>     </tr>      <tr>       <td valign="top" width="158">Authority</td>        <td valign="top" width="462">somewhere.else.com:9999</td>     </tr>      <tr>       <td valign="top" width="158">DnsSafeHost</td>        <td valign="top" width="462">somewhere.else.com</td>     </tr>      <tr>       <td valign="top" width="158">Fragment</td>        <td valign="top" width="462">#fragment</td>     </tr>      <tr>       <td valign="top" width="158">Host</td>        <td valign="top" width="462">somewhere.else.com</td>     </tr>      <tr>       <td valign="top" width="158">HostNameType</td>        <td valign="top" width="462">Dns</td>     </tr>      <tr>       <td valign="top" width="158">IsAbsoluteUri</td>        <td valign="top" width="462">true</td>     </tr>      <tr>       <td valign="top" width="158">IsDefaultPort</td>        <td valign="top" width="462">false</td>     </tr>      <tr>       <td valign="top" width="158">IsFile</td>        <td valign="top" width="462">false</td>     </tr>      <tr>       <td valign="top" width="158">IsLoopback</td>        <td valign="top" width="462">false</td>     </tr>      <tr>       <td valign="top" width="158">IsUnc</td>        <td valign="top" width="462">false</td>     </tr>      <tr>       <td valign="top" width="158">LocalPath</td>        <td valign="top" width="462">/service/packages</td>     </tr>      <tr>       <td valign="top" width="158">OriginalString</td>        <td valign="top" width="462">http://somewhere.else.com:9999/service/packages?page=2#fragment</td>     </tr>      <tr>       <td valign="top" width="158">PathAndQuery</td>        <td valign="top" width="462">/service/packages?page=2</td>     </tr>      <tr>       <td valign="top" width="158">Port</td>        <td valign="top" width="462">9999</td>     </tr>      <tr>       <td valign="top" width="158">Query</td>        <td valign="top" width="462">?page=2</td>     </tr>      <tr>       <td valign="top" width="158">Scheme</td>        <td valign="top" width="462">http</td>     </tr>      <tr>       <td valign="top" width="158">Segments</td>        <td valign="top" width="462">array: “/”, “service/”, “packages”</td>     </tr>      <tr>       <td valign="top" width="158">UserEscaped</td>        <td valign="top" width="462">false</td>     </tr>      <tr>       <td valign="top" width="158">UserInfo</td>        <td valign="top" width="462">“” (empty string)</td>     </tr>   </tbody></table>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/uri-class-cheat-sheet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
	</item>
		<item>
		<title>Windsor Castle: Auto-Wiring Using Parameter Names</title>
		<link>http://igorbrejc.net/development/c/windsor-castle-auto-wiring-using-parameter-names</link>
		<comments>http://igorbrejc.net/development/c/windsor-castle-auto-wiring-using-parameter-names#comments</comments>
		<pubDate>Sun, 11 Jul 2010 15:54:47 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Windsor Castle]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1187</guid>
		<description><![CDATA[NOTE: this is probably only one way of doing things in Windsor Castle. If you know of any other, don’t hesitate to write a comment. A design problem I was trying to solve yesterday: I have a component which depends on two implementations of the same interface: HelpCommand prints out human-readable descriptions of various commands [...]]]></description>
			<content:encoded><![CDATA[<p>NOTE: this is probably only one way of doing things in Windsor Castle. If you know of any other, don’t hesitate to write a comment.</p>

<p>A design problem I was trying to solve yesterday: I have a component which depends on two implementations of the same interface:    
<pre class="brush: csharp; title: ; notranslate">
public class HelpCommand (    
   ICommandDescriptor oneLinerDescriptor,     
   ICommandDescriptor detailedDescriptor)     
{     
   ...     
}     
</pre></p>

<p>HelpCommand prints out human-readable descriptions of various commands in Maperitive. If the user specifies the exact command, HelpCommand prints out a detailed description. On the other hand, if the command parameter is not specified, HelpCommand lists all of the commands and prints a one-liner description for each of them. So there are two implementations of the ICommandDescriptor interface: OneLinerDescriptor and DetailedDescriptor classes.</p>

<p>The problem I was having with this design is that all of my *Command components are registered in one go, using the convention like</p>

<p>
<pre class="brush: csharp; title: ; notranslate">
container.Register (AllTypes.Of&lt;ICommand&gt;().FromAssembly (typeof(ICommand).Assembly)    
   .Configure (c =&gt; c.Named (c.Implementation.Name).LifeStyle.Transient));
</pre></p>

<p>so I’m letting Windsor do all the wiring magic without me being able to provide any custom registration logic for individual commands like HelpCommand. <strong>So how do I tell Windsor which component to use for oneLinerDescriptor and which for detailedDescriptor?</strong></p>

<h3>Bad Solution</h3>

<p>Of course, I could simply specify the concrete implementations in HelpCommand’s constructor:</p>

<p>
<pre class="brush: csharp; title: ; notranslate">
public class HelpCommand (    
   OneLinerDescriptor oneLinerDescriptor,     
   DetailedDescriptor detailedDescriptor)     
{     
   ...     
}     
</pre></p>

<p>But this couples the three classes together and goes against the “rely on abstractions, not implementations” mantra. It also makes unit testing of HelpCommand more difficult, since I have to drag the two descriptor classes around (and they could have their own dependencies to satisfy, which further bloats the unit testing code).</p>

<h3>Factories?</h3>

<p>I could use a factory to get the implementations I need, but that would be wasteful: a simple constructor dependency is much slicker and it doesn’t introduce an additional component (factory) into the picture. Also, factories are more suited for components which are created later, on-demand. In my case I want the descriptors to be available right at the beginning of HelpCommand’s lifecycle.</p>

<h3>Resolving By Name</h3>

<p>So I got an idea: <strong>why not use the name of the constructor parameter as an indicator of what kind of implementation I need</strong>?</p>

<p>This requires writing a custom subresolver:</p>

<p>
<pre class="brush: csharp; title: ; notranslate">
    public class SubDependencyResolverByName : ISubDependencyResolver
    {
        public SubDependencyResolverByName(IKernel kernel, string componentPrefix)
        {
            this.kernel = kernel;
            this.componentPrefix = componentPrefix;
        }

        public bool CanResolve(
            CreationContext context, 
            ISubDependencyResolver contextHandlerResolver, 
            ComponentModel model, 
            DependencyModel dependency)
        {
            if (dependency.IsOptional)
                return false;

            return FindCandidateComponent(dependency.DependencyKey, dependency.TargetType) != null;
        }

        public object Resolve(
            CreationContext context, 
            ISubDependencyResolver contextHandlerResolver, 
            ComponentModel model, 
            DependencyModel dependency)
        {
            ComponentModel dependencyResolvingComponent = FindCandidateComponent (dependency.DependencyKey, dependency.TargetType);
            return kernel.Resolve(dependencyResolvingComponent.Name, dependency.TargetType);
        }

        protected ComponentModel FindCandidateComponent (string dependencyKey, Type targetType)
        {
            foreach (GraphNode node in kernel.GraphNodes)
            {
                ComponentModel visitedComponent = (ComponentModel) node;
                if (visitedComponent.Service != targetType)
                    continue;

                if (componentPrefix == null)
                {
                    if (0 == string.Compare(visitedComponent.Name, dependencyKey, StringComparison.InvariantCultureIgnoreCase))
                        return visitedComponent;
                }
                else
                {
                    if (false == visitedComponent.Name.StartsWith(componentPrefix, StringComparison.InvariantCultureIgnoreCase))
                        continue;

                    string nameWithoutPrefix = visitedComponent.Name.Substring(componentPrefix.Length);
                    if (0 == string.Compare (nameWithoutPrefix, dependencyKey, StringComparison.InvariantCultureIgnoreCase))
                        return visitedComponent;                    
                }
            }

            return null;
        }

        private readonly IKernel kernel;
        private readonly string componentPrefix;
    }
</pre>
</p>

<p>…and attaching it to the container:</p>

<p>
<pre class="brush: css; title: ; notranslate">
container.Kernel.Resolver.AddSubResolver (
   new SubDependencyResolverByName (container.Kernel, &quot;auto_&quot;));
</pre>
</p>

<h3>Results</h3>

<p>Initially I had problems with this new resolver: it tried to be too smart and it messed with the existing (non-problematic) component wiring. So I decided to limit its scope only on dependency components which have a container ID starting with a certain prefix (in my case “auto_”). So if I want OneLinerDescriptor and DetailedDescriptor to be auto-detected by the resolver, I need to register them as “auto_OneLinerDescriptor” and “auto_DetailedDescriptor” in the Windsor container (casing is ignored). The resolver is currently limited to constructor dependencies only, but I see no reason it shouldn’t work for property injections too.</p>

<p>Is name-matching a good approach to auto-wiring components? I don’t know, time will tell. I certainly feel there’s something missing in how Windsor resolves dependencies by the default: type-matching is fine for simple scenarios, but as soon as you have more than one implementation of the same service interface, you need to specify service overrides or rely on &quot;black magic” to wire things for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/windsor-castle-auto-wiring-using-parameter-names/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
	</item>
		<item>
		<title>System.Web.HttpRequest Paths Cheat Sheet</title>
		<link>http://igorbrejc.net/development/c/system-web-httprequest-paths-cheat-sheet</link>
		<comments>http://igorbrejc.net/development/c/system-web-httprequest-paths-cheat-sheet#comments</comments>
		<pubDate>Wed, 07 Jul 2010 13:33:41 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/c/system-web-httprequest-paths-cheat-sheet</guid>
		<description><![CDATA[More a “remember” post for me than a real reference thing, but I think it might be useful to anybody doing more than simple work with HttpRequests. Example request URL: http://localhost:65107/Services.svc/services?page=30 The table below contains values for various path-related properties of HttpRequest for that example request URL: ApplicationPath / AppRelativeCurrentExecutionFilePath ~/Services.svc CurrentExecutionFilePath /Services.svc FilePath /Services.svc [...]]]></description>
			<content:encoded><![CDATA[<p>More a “remember” post for me than a real reference thing, but I think it might be useful to anybody doing more than simple work with HttpRequests.</p>

<p>Example request URL: <strong>http://localhost:65107/Services.svc/services?page=30</strong></p>

<p>The table below contains values for various path-related properties of <strong>HttpRequest</strong> for that example request URL:</p>

<table border="1" cellspacing="0" cellpadding="5" width="622"><tbody>     <tr>       <td valign="top" width="309">ApplicationPath</td>        <td valign="top" width="311">/</td>     </tr>      <tr>       <td valign="top" width="309">AppRelativeCurrentExecutionFilePath</td>        <td valign="top" width="311">~/Services.svc</td>     </tr>      <tr>       <td valign="top" width="309">CurrentExecutionFilePath</td>        <td valign="top" width="311">/Services.svc</td>     </tr>      <tr>       <td valign="top" width="309">FilePath</td>        <td valign="top" width="311">/Services.svc</td>     </tr>      <tr>       <td valign="top" width="309">Path</td>        <td valign="top" width="311">/Services.svc/services</td>     </tr>      <tr>       <td valign="top" width="309">PathInfo</td>        <td valign="top" width="311">/services</td>     </tr>      <tr>       <td valign="top" width="309">PhysicalApplicationPath</td>        <td valign="top" width="311">D:\svn\eEnvoyer\SEPA\EEnvoyer.Server\</td>     </tr>      <tr>       <td valign="top" width="309">PhysicalPath</td>        <td valign="top" width="311">D:\svn\eEnvoyer\SEPA\EEnvoyer.Server\Services.svc</td>     </tr>      <tr>       <td valign="top" width="309">RawUrl</td>        <td valign="top" width="311">/Services.svc/services?page=30</td>     </tr>      <tr>       <td valign="top" width="309">Url</td>        <td valign="top" width="311">http://localhost:65107/Services.svc/services?page=30</td>     </tr>   </tbody></table>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/system-web-httprequest-paths-cheat-sheet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
	</item>
		<item>
		<title>Windows Services And Working Directories</title>
		<link>http://igorbrejc.net/development/c/windows-services-and-working-directories</link>
		<comments>http://igorbrejc.net/development/c/windows-services-and-working-directories#comments</comments>
		<pubDate>Sun, 25 Apr 2010 19:52:08 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[guidelines]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/c/windows-services-and-working-directories</guid>
		<description><![CDATA[A reminder for me: when developing Windows services, in the initialization code set the Environment.CurrentDirectory to the directory where your binaries are located: string applicationFullPath = Assembly.GetExecutingAssembly().Location;string applicationDirectory = Path.GetDirectoryName( Path.GetFullPath(applicationFullPath));log.InfoFormat( &#34;Setting the current directory to '{0}'...&#34;, applicationDirectory);Environment.CurrentDirectory = applicationDirectory; This helps avoiding problems with .NET framework implicitly accessing various file resources stored together with [...]]]></description>
			<content:encoded><![CDATA[<p>A reminder for me: when developing Windows services, in the initialization code set the <strong>Environment.CurrentDirectory</strong> to the directory where your binaries are located:</p>

<div>   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">string</span> applicationFullPath = Assembly.GetExecutingAssembly().Location;<br /><span style="color: #0000ff">string</span> applicationDirectory = Path.GetDirectoryName(<br />    Path.GetFullPath(applicationFullPath));<br /><br />log.InfoFormat(<br />    <span style="color: #006080">&quot;Setting the current directory to '{0}'...&quot;</span>, <br />    applicationDirectory);<br />Environment.CurrentDirectory = applicationDirectory;</pre>
</div>

<p>This helps avoiding problems with .NET framework implicitly accessing various file resources stored together with your binaries. I had a situation where I wanted to validate an XML file using XSD schema files stored in my application directory. The code worked OK in the integration tests but failed when run inside a Windows service. It turns out .NET Framework’s XML validation code wanted to import certain dependent XSD schema files from the current directory, which is, in the case of Windows services, <strong>C:\Windows\System32 </strong>by default. Of course, the needed XSD files weren’t there, but the validation code doesn’t really tell you this, it just reports an unhelpful validation error.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/windows-services-and-working-directories/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
	</item>
		<item>
		<title>Kerning Or How To Outfox GDI+</title>
		<link>http://igorbrejc.net/development/c/kerning-or-how-to-outfox-gdi</link>
		<comments>http://igorbrejc.net/development/c/kerning-or-how-to-outfox-gdi#comments</comments>
		<pubDate>Thu, 22 Apr 2010 18:56:30 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Cartography]]></category>
		<category><![CDATA[Maperitive]]></category>
		<category><![CDATA[OpenStreetMap]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/c/kerning-or-how-to-outfox-gdi</guid>
		<description><![CDATA[(image taken from Wikipedia) I’m working on a text-on-path algorithm for Maperitive to be able to render things like street names. GDI+ does not have a built-in function for drawing texts on a path, so I’m stuck with writing my own. Although there are a lot of implementations of such an algorithm out there, they [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://igorbrejc.net/wp-content/uploads/2010/04/500pxMetal_type_kerning.svg1_.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="500px-Metal_type_kerning.svg[1]" border="0" alt="500px-Metal_type_kerning.svg[1]" src="http://igorbrejc.net/wp-content/uploads/2010/04/500pxMetal_type_kerning.svg1_thumb.png" width="404" height="244" /></a> (image taken from <a href="http://en.wikipedia.org/wiki/Kerning" target="_blank">Wikipedia</a>)</p>

<p>I’m working on a text-on-path algorithm for Maperitive to be able to render things like street names. GDI+ does not have a built-in function for drawing texts on a path, so I’m stuck with writing my own.</p>

<p>Although there are <a href="http://www.codeproject.com/KB/GDI-plus/Text_on_Path_with_VBNET.aspx" target="_blank">a lot</a> <a href="http://www.planetclegg.com/projects/WarpingTextToSplines.html" target="_blank">of implementations</a> of such an algorithm out there, they all miss one important thing: <a href="http://en.wikipedia.org/wiki/Kerning" target="_blank">kerning</a>. Kerning is basically telling a character to move a bit closer to its neighbor if there is enough space for them to huddle together:</p>

<p><a href="http://igorbrejc.net/wp-content/uploads/2010/04/Kerning1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Kerning[1]" border="0" alt="Kerning[1]" src="http://igorbrejc.net/wp-content/uploads/2010/04/Kerning1_thumb.png" width="236" height="167" /></a> (image taken from <a href="http://en.wikipedia.org/wiki/File:Kerning.png" target="_blank">Wikipedia</a>)</p>

<p>Since the path can consist of several line segments (and even curves), you need to render each character (glyph to be more precise) separately to be able to rotate it using the angle of the line segment it will be drawn on. The problem is determining how far from the previous character to place the next character. GDI+ offers a method called <a href="http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx" target="_blank">MeasureString</a>, but calling it on a single isolated character returns a character width value without any kerning taken into account, so characters like V and A can appear too spread apart. There is another method, <a href="http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurecharacterranges.aspx" target="_blank">MeasureCharacterRanges</a>, which can measure each individual character width for a given text, but it has a practical limit of 32 characters and is pretty processor- and resource-intensive. I’ve used it for the text-on-path algorithm for Kosmos but the results weren’t very satisfactory.</p>

<p>From my (basic) understanding of how kerning usually works on computer typography, a font which has kerning information stores kerning offsets for character pairs. So, for example, V and A will have a different (usually stronger) kerning than say, character pair V and T. The problem with GDI+ is that you don’t really have access to this information.</p>

<p>One option would be to use <a href="http://msdn.microsoft.com/en-us/library/dd144821%28v=VS.85%29.aspx" target="_blank">old GDI’s font and text functions</a> to fetch the information about the kerning pairs, but these need to be P/invoked and thus will probably not work on Mono, which makes them unusable for Maperitive – I’m really trying to make Maperitive run on multiple platforms.</p>

<p>So after spending a day in brainstorming, I got an idea on how to handle kerning myself. It’s really simple: I will calculate the kerning myself (using the mentioned MeasureString method). The formula is simple:</p>

<blockquote>   <p>&lt;character kerned width&gt; = &lt;character non-kerned width&gt; &#8211; (&lt;character pair non-kerned width&gt; &#8211; &lt;character pair kerned width&gt;)</p> </blockquote>

<p>I can get all of the three values on the right of the equation using the MeasureString: first I’ll measure each character’s individual (non-kerned) width and then I’ll measure the width when they are drawn together. The difference between these is the actual kerning, which is then used to calculate the kerned width of the first character.</p>

<p>The added twist to this tale is that I’ll keep this information in a cache, to keep the expensive calls to the MeasureString method to the minimum. This cache could even be persisted to the disk. Of course, each font family and font style dictates its own kerning, so the cache needs to be extended with this information.</p>

<p>One potential problem is how to handle kerning information for different font heights. Since Maperitive supports continuous zooming levels, the number of different font heights used is (almost) limitless. I’ve decided to cut some corners here: the kerning will be calculated (and stored) for some nominal font height (say 100 em) and then interpolated for any needed height. We&#8217;ll see how that goes… next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/kerning-or-how-to-outfox-gdi/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:thumbnail url="http://igorbrejc.net/wp-content/uploads/2010/04/500pxMetal_type_kerning.svg1_thumb.png" />
		<media:content url="http://igorbrejc.net/wp-content/uploads/2010/04/500pxMetal_type_kerning.svg1_thumb.png" medium="image">
			<media:title type="html">500px-Metal_type_kerning.svg[1]</media:title>
		</media:content>
		<media:content url="http://igorbrejc.net/wp-content/uploads/2010/04/Kerning1_thumb.png" medium="image">
			<media:title type="html">Kerning[1]</media:title>
		</media:content>
	</item>
		<item>
		<title>Disposing Of The Evidence</title>
		<link>http://igorbrejc.net/development/c/disposing-of-the-evidence</link>
		<comments>http://igorbrejc.net/development/c/disposing-of-the-evidence#comments</comments>
		<pubDate>Fri, 05 Mar 2010 12:12:00 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Windsor Castle]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1046</guid>
		<description><![CDATA[photo credit: wok In the previous post we discussed various relationships between singletons and transients in an inversion of control container. I introduced WindsorContainerInspector, a little utility class for analyzing the container and showed a sample unit test which looks for singletons that rely on transient objects. Now I’ll show a few other checks that [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/67566398@N00/108876881/" title="Garbage?" target="_blank"><img src="http://farm1.static.flickr.com/48/108876881_fc305b32f7_m.jpg" alt="Garbage?" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-nc-nd/2.0/" title="Attribution-NonCommercial-NoDerivs License" target="_blank"><img src="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/67566398@N00/108876881/" title="wok" target="_blank">wok</a></small></p>

<p>In the <a href="http://igorbrejc.net/?p=1026" target="_blank">previous post</a> we discussed various relationships between singletons and transients in an inversion of control container. I introduced <strong>WindsorContainerInspector</strong>, a little utility class for analyzing the container and showed a sample unit test which looks for singletons that rely on transient objects.</p>

<p>Now I’ll show a few other checks that I think are good to perform on the container. They involve disposability of objects.</p>

<h3>Disposable Transients</h3>

<p>Let’s say we have a transient service <strong>IWebClient</strong>:</p>

<div id="codeSnippetWrapper">   <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IWebClient : IDisposable<br />{<br />    <span style="color: #0000ff">void</span> DownloadMeSomething(<span style="color: #0000ff">string</span> somethingUrl);<br />}</pre>

  <br /></div>

<p>As you can see, the service implements IDisposable. Now let’s say we have a class <strong>DownloadData </strong>which depends on this service:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DownloadData<br />{<br />    <span style="color: #0000ff">public</span> DownloadData (IWebClient webClient) {...}<br /><br />    ...<br />}</pre>
</div>

<p>Note the constructor dependency on IWebClient. What’s wrong with this picture?</p>

<p>What happens when the DownloadData is no longer used? The webClient is not disposed. We could hold up some valuable system resource by not disposing of such an object. And since we know IWebClient is defined as transient in our IoC container, we can be pretty sure that DownloadData is the only one using the received IWebClient instance. So we are responsible for this instance!</p>

<p>In other words, our DownloadData should also be disposable. We can say that, in general, <em>components that depend on disposable transients should also be disposable</em>:</p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">[Test, MultipleAsserts]</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> TransientsThatRelyOnDisposableTransientsShouldAlsoBeDisposable ()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    Type disposableType = <span style="color: #0000ff">typeof</span>(IDisposable);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    IList&lt;KeyValuePair&lt;ComponentModel, ComponentModel&gt;&gt; dependencies = inspector.FindDependencies (</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        (a, b) =&gt;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">return</span> a.LifestyleType == LifestyleType.Transient &amp;&amp; <span style="color: #0000ff">false</span> == disposableType.IsAssignableFrom (a.Implementation)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                &amp;&amp; b.LifestyleType == LifestyleType.Transient &amp;&amp; disposableType.IsAssignableFrom(b.Service);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        });</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">foreach</span> (KeyValuePair&lt;ComponentModel, ComponentModel&gt; dependency <span style="color: #0000ff">in</span> dependencies)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        Assert.Fail (</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            <span style="color: #006080">&quot;Transient component {0} relies on the disposable transient component {1}, but it itself is not disposable&quot;</span>,</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            dependency.Key.Implementation.FullName,</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            dependency.Value.Implementation.FullName);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
<!--CRLF--></div>
</div>

<p>Some might say that this kind of check can be done by static analysis like FxCop. FxCop will detect this only if DownloadData stores the IWebClient in a class field. But we could have used IWebClient parameter just within the constructor and then forget about it:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> DownloadData<br />{    <br />    <span style="color: #0000ff">public</span> DownloadData (IWebClient webClient) <br />    {<br />        webClient.CheckConnection();<br />    }    <br />}</pre>

  <br /></div>

<p>In such cases no warning will be issued by FxCop.</p>

<h3>Disposable Implementations Of Non-Disposable Services</h3>

<p>What if we had another service, called IMailChecker:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> IMailChecker<br />{<br />    <span style="color: #0000ff">bool</span> AnyNewMail();<br />}</pre>

  <br /></div>

<p>and we implemented a GMailChecker:</p>

<div id="codeSnippetWrapper">
  <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> GMailChecker : IMailChecker, IDisposable<br />{    <br />    <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> AnyNewMail() {...}<br />    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Dispose() {...}<br />}</pre>

  <br /></div>

<p>Notice GMailChecker implements IDisposable in addition to IMailChecker interface. But IMailChecker itself is not defined as disposable. How will the user of IMailChecker service know whether the object it holds should be disposed or not?</p>

<p>One way would be to use reflection to determine this. But this is very cumbersome and easy to forget when coding. My way of thinking is that <em>if there’s reasonable possibility the implementations of the service will require disposability, you should declare the service interface as disposable</em>. We can check for this condition with the following unit test:</p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">[Test, MultipleAsserts]</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> TransientsThatRelyOnDisposableTransientsShouldAlsoBeDisposable ()</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    Type disposableType = <span style="color: #0000ff">typeof</span>(IDisposable);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    IList&lt;KeyValuePair&lt;ComponentModel, ComponentModel&gt;&gt; dependencies = inspector.FindDependencies (</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        (a, b) =&gt;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">return</span> a.LifestyleType == LifestyleType.Transient &amp;&amp; <span style="color: #0000ff">false</span> == disposableType.IsAssignableFrom (a.Implementation)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                &amp;&amp; b.LifestyleType == LifestyleType.Transient &amp;&amp; disposableType.IsAssignableFrom(b.Service);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        });</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">foreach</span> (KeyValuePair&lt;ComponentModel, ComponentModel&gt; dependency <span style="color: #0000ff">in</span> dependencies)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        Assert.Fail (</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            <span style="color: #006080">&quot;Transient component {0} relies on the disposable transient component {1}, but it itself is not disposable&quot;</span>,</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            dependency.Key.Implementation.FullName,</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            dependency.Value.Implementation.FullName);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
<!--CRLF--></div>
</div>

<p>Below is the updated the implementation of WindsorContainerInspector. Next time we will be discussing issues (= mostly problems) around disposing stuff received from the Windsor container. </p>

<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
  <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> WindsorContainerInspector</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">public</span> WindsorContainerInspector(IWindsorContainer container)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">this</span>.container = container;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">public</span> IList&lt;KeyValuePair&lt;ComponentModel, ComponentModel&gt;&gt; FindDependencies(</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        Func&lt;ComponentModel, ComponentModel, <span style="color: #0000ff">bool</span>&gt; dependencyPredicate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        List&lt;KeyValuePair&lt;ComponentModel, ComponentModel&gt;&gt; dependencies = <span style="color: #0000ff">new</span> List&lt;KeyValuePair&lt;ComponentModel, ComponentModel&gt;&gt;();</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">foreach</span> (GraphNode node <span style="color: #0000ff">in</span> container.Kernel.GraphNodes)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            ComponentModel dependingNode = (ComponentModel) node;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">foreach</span> (GraphNode depender <span style="color: #0000ff">in</span> node.Dependents)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                ComponentModel dependerNode = (ComponentModel)depender;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                <span style="color: #0000ff">if</span> (dependencyPredicate(dependingNode, dependerNode))</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                    dependencies.Add(<span style="color: #0000ff">new</span> KeyValuePair&lt;ComponentModel, ComponentModel&gt;(dependingNode, dependerNode));</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">return</span> dependencies;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">public</span> IList&lt;ComponentModel&gt; FindComponents (Func&lt;ComponentModel, <span style="color: #0000ff">bool</span>&gt; predicate)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        List&lt;ComponentModel&gt; components = <span style="color: #0000ff">new</span> List&lt;ComponentModel&gt;();</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">foreach</span> (GraphNode node <span style="color: #0000ff">in</span> container.Kernel.GraphNodes)</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        {</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            ComponentModel component = (ComponentModel) node;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            <span style="color: #0000ff">if</span> (predicate(component))</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">                components.Add(component);</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        <span style="color: #0000ff">return</span> components;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    }</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    <span style="color: #0000ff">private</span> <span style="color: #0000ff">readonly</span> IWindsorContainer container;</pre>
<!--CRLF-->

    <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
<!--CRLF--></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/c/disposing-of-the-evidence/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://farm1.static.flickr.com/48/108876881_fc305b32f7_m.jpg" />
		<media:content url="http://farm1.static.flickr.com/48/108876881_fc305b32f7_m.jpg" medium="image">
			<media:title type="html">Garbage?</media:title>
		</media:content>
		<media:content url="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" medium="image">
			<media:title type="html">Creative Commons License</media:title>
		</media:content>
	</item>
	</channel>
</rss>

