<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="http://feedproxy.google.com/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feedproxy.google.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Inquisitive Coder - Davy Brion's Blog</title>
	
	<link>http://davybrion.com/blog</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<pubDate>Sun, 04 Jan 2009 21:07:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feedproxy.google.com/davybrion" type="application/rss+xml" /><item>
		<title>NHibernate Profiler Review</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/LL19IzN-iIY/</link>
		<comments>http://davybrion.com/blog/2009/01/nhibernate-profiler-review/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 21:07:53 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=807</guid>
		<description><![CDATA[A Profiler For NHibernate? What&#8217;s The Point?
If you&#8217;re not very experienced with NHibernate, it&#8217;s not always clear what NHibernate is doing behind the scenes.  What kind of queries is it generating? How many entities are we loading? How often does it go the database?  Even experienced NHibernate users can make mistakes which may [...]]]></description>
			<content:encoded><![CDATA[<h4>A Profiler For NHibernate? What&#8217;s The Point?</h4>
<p>If you&#8217;re not very experienced with NHibernate, it&#8217;s not always clear what NHibernate is doing behind the scenes.  What kind of queries is it generating? How many entities are we loading? How often does it go the database?  Even experienced NHibernate users can make mistakes which may result in inefficient data access, high memory usage, slow response times, etc.  When used properly however, you can get excellent performance out of NHibernate.  </p>
<p>According to the <a href="http://nhprof.com/">website</a>, NHibernate Profiler delivers the following advantages:</p>
<ul>
<li>Cognitive application awareness</li>
<li>Visual insight into the interaction between your database and application code</li>
<li>Analysis and detection of common pitfalls when using NHibernate</li>
<li>Analysis is delivered via perfectly styled SQL and linkable code execution</li>
</ul>
<p>Sounds pretty good, right? Let&#8217;s take a closer look.</p>
<h4>What is NHibernate Doing?</h4>
<p>To get a good view on what NHibernate is doing, you should get answers to questions like:</p>
<ul>
<li>How many statements are we sending to the database?</li>
<li>What statements are we sending to the database?</li>
<li>What data are we loading into memory?</li>
</ul>
<p>NHibernate Profiler makes it easy to anser those questions.  For an NHibernate session where we send a simple query to the database, the profiler already gives us some useful information:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh01.png" alt="nh01" title="nh01" width="756" height="395" class="aligncenter size-full wp-image-811" /></p>
<p>In the Statements tab, you get an overview of all of the statements in this session.  When you select one of the statements, you can view more details in the tabs on the bottom.  In this screenshot, you see a properly formatted SQL query which is the query that was generated by NHibernate.  The overview also shows how many rows were retrieved by the query.</p>
<p>So we know how many entities were loaded, but which ones were they? Again, the profiler gives us some useful information on that:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh02.png" alt="nh02" title="nh02" width="758" height="220" class="aligncenter size-full wp-image-812" /></p>
<p>The Entities tab shows you the identifiers of each entity instance (grouped by type) that was retrieved in the session.  There&#8217;s also a useful general overview of your session usage:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh03.png" alt="nh03" title="nh03" width="757" height="267" class="aligncenter size-full wp-image-813" /></p>
<p>Looks like the profiler is already alerting us of a possible problem.  Let&#8217;s go the Alerts tab:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh04.png" alt="nh04" title="nh04" width="757" height="337" class="aligncenter size-full wp-image-815" /></p>
<p>You can see the alert right there, with a link to a help page on the profiler&#8217;s website with a more detailed explanation.  The help pages are very helpful and always suggest a way to avoid the problem.  In this case, the problem is that our query returns the rows of a table without limiting the number of rows to be returned.  In some cases, this can really be a problem but if you&#8217;re really sure that the table will always have just a few records then it&#8217;s not really a problem.  A helpful extra feature here would be to mark the alert with some sort of &#8220;i know about this, and i don&#8217;t consider it a problem&#8221; action so it is removed from the profiler&#8217;s output.   This specific alert can be disabled altogether as well, although i think it would be more useful to remove these alerts on a case-by-case basis.</p>
<p>Now, we know what NHibernate is doing which is pretty useful, but we also need an easy way to figure out which piece of code caused the SQL statements to be sent to the database.  The profiler allows you to look at a stacktrace when you select a statement:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh05.png" alt="nh05" title="nh05" width="757" height="437" class="aligncenter size-full wp-image-816" /></p>
<p>You can double click at each entry in the stacktrace and Visual Studio will show you that line of source code. </p>
<p>I think it&#8217;s clear that the profiler does a good job of showing you what NHibernate is doing behind the scenes.  The output that the profiler is showing you is very useful as well:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh06.png" alt="nh06" title="nh06" width="757" height="702" class="aligncenter size-full wp-image-817" /></p>
<p>This is the output of a batch of queries.  Notice how the queries are nicely separated, and that the parameter values are already filled in.  You can easily copy these select statements to execute the queries in whatever querying tool you&#8217;d like to use so you can study the actual output of a query.  Another nice extra feature would be the ability to select a statement and have the profiler execute it against the database and showing you the results in a separate window.</p>
<p>I hope to see more information regarding the usage of NHibernate&#8217;s 2nd Level Cache in a future version of this profiler.  It would be great to see which entity instances are stored in the cache, when they are stored and through which query, when they are retrieved from the cache instead of the database, when they expire from the cache, when they get refreshed, etc&#8230;  </p>
<h4>What are YOU doing?</h4>
<p>Alright, we already covered how the profiler shows what NHibernate is doing.  That&#8217;s nice.  But do you know what you&#8217;re doing? Are you sure you&#8217;re using NHibernate properly?  The profiler has a couple of nice features to warn you from mistakes you might make.  As you saw earlier in this review, the profiler alerts you when you do something that might be problematic.</p>
<p>The profiler currently has the ability to alert you of the following problems:</p>
<ul>
<li>Select N + 1</li>
<li>Too many database calls in a session</li>
<li>Unbounded result set</li>
<li>Excessive number of rows</li>
<li>Usage of implicit transactions</li>
<li>Large number of writes</li>
</ul>
<p>The profiler offers guidance for each type of alert, making it clear how you can avoid the problem by suggesting other approaches.  This guidance is offered through the website of the profiler (the application provides links), but it might be a nice idea to show that guidance from within the tool as well.</p>
<p>Here&#8217;s an example of the Select N + 1 problem:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh07.png" alt="nh07" title="nh07" width="757" height="349" class="aligncenter size-full wp-image-818" /></p>
<p>As you can see here, the same query is executed 4 times with an ID parameter that differs each time. Naturally, it would be much better if this data was fetched in one query instead of 4.  The profiler clearly alerts you to the problem, and through the stacktrace tab you can very easily navigate to the part of code that is causing the problem.</p>
<p>It&#8217;s also worth pointing out that you can modify the settings which trigger these alerts:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh08.png" alt="nh08" title="nh08" width="431" height="298" class="aligncenter size-full wp-image-820" /></p>
<h4>Overview Features</h4>
<p>Looking at what each individual session is doing is useful, but sometimes you kind of want an overview of the overall NHibernate usage of your application.  NHibernate Profiler offers 4 extra views on what&#8217;s going on in your application.</p>
<p>The first is an overview of all of the queries that were executed during the run:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh09.png" alt="nh09" title="nh09" width="755" height="299" class="aligncenter size-full wp-image-821" /></p>
<p>This is useful, but i think it would be better if the grid included the average duration for each query.  Also, a way to navigate from one of the queries to where it is triggered in code would be great here.</p>
<p>There&#8217;s also an overview of the queries that were triggered by class and method:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh10.png" alt="nh10" title="nh10" width="961" height="706" class="aligncenter size-full wp-image-822" /></p>
<p>In this view it would also be very useful to show more information about average durations of statements.</p>
<p>The third one is a general overview of your overall NHibernate usage:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh11.png" alt="nh11" title="nh11" width="808" height="700" class="aligncenter size-full wp-image-824" /></p>
<p>This one is very nice&#8230; the aggregated alerts pane is great, but when you click on the links next to the alerts a browser window will open with relevant alert information from the profiler&#8217;s website.  I think it might be easier if you could just navigate from these aggregated alerts to the specific sessions which are causing these.  For instance, if i have a SELECT N + 1 alert in there, i would like to have a way to go to the data from that specific session (or the sessions) with as little clicks and searching as possible.</p>
<p>The aggregated entities and the general statistics are also a very nice touch.</p>
<p>And finally, you can also keep track of the stats that NHibernate itself provides:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2009/01/nh12.png" alt="nh12" title="nh12" width="310" height="282" class="aligncenter size-full wp-image-825" /></p>
<h4>Conclusions</h4>
<p>I&#8217;ve been playing with this profiler for a couple of weeks now, and i definitely like it a lot.  It not only does a great job of quickly pinpointing problems, it also does a good job of teaching users how to properly use NHibernate.  It not only saves you time when you need to fix a problem, it enables you to fix the problem in an informed manner.  It&#8217;s got some great features already, and there will probably be many more interesting additions to the profiler in the future.  Is this profiler worth the cost of the license? I&#8217;d say it definitely is.  Not just for the time you&#8217;ll save because of it, but also for the stuff you&#8217;ll learn from it.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=NHibernate%20Profiler%20Review&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F01%2Fnhibernate-profiler-review%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/q9JGrJT1p1qEkrp2-i_zw9U418c/a"><img src="http://feedads.googleadservices.com/~a/q9JGrJT1p1qEkrp2-i_zw9U418c/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/LL19IzN-iIY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2009/01/nhibernate-profiler-review/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2009/01/nhibernate-profiler-review/</feedburner:origLink></item>
		<item>
		<title>NHibernate Profiler Is Now Available</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/nBau9y3Df6o/</link>
		<comments>http://davybrion.com/blog/2009/01/nhibernate-profiler-is-now-availabl/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 00:28:34 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=803</guid>
		<description><![CDATA[As Ayende already said, the NHibernate Profiler is now in public beta.  If you&#8217;re using NHibernate, do yourself a favor and try this tool because it really is great.
Oh, and Ayende has a 30% discount on licenses at the moment&#8230; i&#8217;d take advantage of that if i were you  

    [...]]]></description>
			<content:encoded><![CDATA[<p>As Ayende already <a href="http://ayende.com/Blog/archive/2009/01/02/nh-prof-is-in-public-beta.aspx">said</a>, the <a href="http://nhprof.com/">NHibernate Profiler</a> is now in public beta.  If you&#8217;re using NHibernate, do yourself a favor and try this tool because it really is great.</p>
<p>Oh, and Ayende has a 30% discount on licenses at the moment&#8230; i&#8217;d take advantage of that if i were you <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=NHibernate%20Profiler%20Is%20Now%20Available&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F01%2Fnhibernate-profiler-is-now-availabl%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/CizKVeyhrzm1fRC6m0uumbM9gM0/a"><img src="http://feedads.googleadservices.com/~a/CizKVeyhrzm1fRC6m0uumbM9gM0/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/nBau9y3Df6o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2009/01/nhibernate-profiler-is-now-availabl/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2009/01/nhibernate-profiler-is-now-availabl/</feedburner:origLink></item>
		<item>
		<title>The Life And Times Of A Bug</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/hF6s2L4IzfU/</link>
		<comments>http://davybrion.com/blog/2009/01/the-life-and-times-of-a-bug/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 16:52:40 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=789</guid>
		<description><![CDATA[October 15, 2008
My birthday. I am not sure yet what events led to my existence but here i am anyway.  I have no idea what i am, what i&#8217;m supposed to do or what my purpose in life is.  But there are a few more of my kind running around here.  I [...]]]></description>
			<content:encoded><![CDATA[<p><strong>October 15, 2008</strong></p>
<p>My birthday. I am not sure yet what events led to my existence but here i am anyway.  I have no idea what i am, what i&#8217;m supposed to do or what my purpose in life is.  But there are a few more of my kind running around here.  I guess i better go find out.</p>
<p><strong>October 23, 2008</strong></p>
<p>Apparently, i&#8217;m a bug.  A software bug if you want to be specific.  My brothers and sisters told me that we are a byproduct of an activity that occurs between code and developers.  That activity being screwing around without proper protection.  It means that a developer made a mistake somewhere, and then we come in.  Some of us remain dormant, never to be discovered while most of us are spotted sooner or later.  Some of us can wreak havoc when we are triggered, while others just cause minor inconveniences.  I don&#8217;t quite understand everything yet, but it appears that we are no good.  We cause problems and nobody seems to like us.  So why are we here? </p>
<p><strong>October 30, 2008</strong></p>
<p>It&#8217;s been another pretty boring week&#8230; i haven&#8217;t been triggered yet, so i&#8217;ve had plenty of time to seek answers to the questions that i still have.  Most people deride us, because they claim we are only costing people money.  In some way, that&#8217;s true.  But we are a necessary evil in the field of software development.  Our purpose is to force software developers to step their game up.  If they mess up, we punish them with everything we&#8217;ve got in the hope that they at least learn something from the mistakes they make.  If the developers are smart, they make sure to put protective countermeasures in place so fixed bugs can&#8217;t reappear, or that similar bugs can&#8217;t be created.  We also sometimes manage to keep big headed developers grounded.  After all, most of them think they&#8217;re some kind of gods because they&#8217;re oh so smart and clever and because they are &#8216;creating&#8217; things.  If it weren&#8217;t for us, there would be nothing to keep them from feeling superior to everyone else.</p>
<p><strong>December 3, 2008</strong></p>
<p>One of my brothers got &#8216;fixed&#8217; today.  That&#8217;s how the developers call it.  Fixed.  That&#8217;s quite a euphemism considering the fact that it actually means one of us was killed.  I know that this is a part of our job, but that doesn&#8217;t mean it&#8217;s an easy thing to deal with.  My resentment towards developers is growing every day.  You know, we&#8217;re doing our part&#8230; but developers don&#8217;t really seem to learn too much from the mistakes they make, considering our prominence in the history of software development.  Bringing us in this world just to kill us is cruel enough, but do they really need to create more and more of us just so we can be killed? It all seems so pointless. </p>
<p><strong>December 5, 2008</strong></p>
<p>Uh-oh&#8230; i&#8217;ve been triggered.  This is the first time i was triggered in this code base and i&#8217;m not sure how to feel about it.  A part of me is anxious to complete my task, but i&#8217;m starting to like it here&#8230; i don&#8217;t want to go so soon&#8230; i&#8217;d much rather stick around for a while so i can hopefully make it to one of the maintenance branches.</p>
<p><strong>December 6, 2008</strong></p>
<p>Hmm, i haven&#8217;t been triggered anymore so i guess nobody wrote a test case to truly expose me yet.  I feel good about that, but i am getting more nervous with each passing hour.</p>
<p><strong>December 16, 2008</strong></p>
<p>My worst fears have been confirmed.  I&#8217;ve been discovered and someone is triggering me over and over again.  I looked into the subversion commit logs (yes, we can actually do that) and some guy with username &#8216;davybrion&#8217; committed a test case.   Great&#8230; the rookie of the team.  Probably has a chip on his shoulder too&#8230; feels like he has to prove something.  I hate these guys.  I&#8217;ve been given a name too&#8230; <a href="http://jira.nhibernate.org/browse/NH-1609">NH-1609</a>.  Gee, thanks.  Now i really feel like a number in a system.  These developers&#8230; arrogant pricks!</p>
<p><strong>December 22, 2008</strong></p>
<p>I&#8217;ve got a headache&#8230; i&#8217;ve been running for a while now, with a debugger attached.  That&#8217;s a lot harder than running in a normal environment, trust me.  No code has been changed yet, but i think this &#8216;davybrion&#8217; guy found my exact location.  He appears to be exploring his options for killing me.  Oh sorry, i mean &#8216;fixing&#8217; me. I can hear him swearing and cursing too&#8230; i even heard him say he&#8217;s definitely gonna &#8216;fix&#8217; me.  What an over-confident, foul-mouthed prick. </p>
<p><strong>December 24, 2008</strong></p>
<p>It&#8217;s night time, and i haven&#8217;t been triggered for a couple of days.  Time to enjoy Christmas Eve with my fellow bugs!  We&#8217;re going to enjoy a nice meal, have some wine, and debate on which of the developers we despise most.  My vote is for &#8216;davybrion&#8217;.  </p>
<p><strong>December 27, 2008</strong></p>
<p>It&#8217;s been pretty quiet around here&#8230; no modifications to the code that i can interfere with.  Which is too bad because i&#8217;m eager to spawn some kids of my own.  Everybody wants to leave a legacy when they go.</p>
<p><strong>December 29, 2008&#8230;. 10PM</strong></p>
<p>Well, he&#8217;s at it again.  I&#8217;m constantly being triggered and i&#8217;ve got a bad feeling about this.  &#8216;davybrion&#8217; is changing code left and right.  He seems to have found the root cause of my existence, and he&#8217;s changing a lot of code&#8230; he&#8217;s taking a lot of risks&#8230; procreation, here i come!</p>
<p><strong>December 29, 2008&#8230; 11:30PM</strong></p>
<p>Hah, this rookie screwed around&#8230; i&#8217;m a proud father now!</p>
<p><strong>December 29, 2008&#8230; 11:55PM</strong></p>
<p>Damn it! He must have realized the risk he was taking and he reverted all of his changes.  He killed my babies before they were ever committed!</p>
<p><strong>December 30, 2008&#8230; 7PM</strong></p>
<p>Oh great, he&#8217;s back for more&#8230; I can&#8217;t wait for him to screw this up again.</p>
<p><strong>December 30, 2008&#8230; 8:28PM</strong></p>
<p>Oh crap&#8230; i think he&#8217;s got a fix ready&#8230; this is gonna be the end of me&#8230; i can feel it <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><strong>December 30, 2008&#8230; 8:30PM</strong></p>
<p>He ran all of the tests and i didn&#8217;t get activated&#8230; I guess that&#8217;s it for me.  I can&#8217;t believe this rookie got the best of me.  He claims he&#8217;s not happy with how he had to fix me (yes, i can spy on his IM messages and his email) and he wants to refactor an important part of this code base.  At least he realizes it&#8217;s too risky to do this with their next release in mind.  Perhaps this prick did learn something from all of this.  Oh well, i can only hope so.  I still don&#8217;t like developers though&#8230; we can&#8217;t live with them, but we can&#8217;t really live without them either.  It&#8217;s a complicated relationship really.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=The%20Life%20And%20Times%20Of%20A%20Bug&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F01%2Fthe-life-and-times-of-a-bug%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/DrT3dj5e8rSqvlAB4LGu-ZbvkNU/a"><img src="http://feedads.googleadservices.com/~a/DrT3dj5e8rSqvlAB4LGu-ZbvkNU/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/hF6s2L4IzfU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2009/01/the-life-and-times-of-a-bug/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2009/01/the-life-and-times-of-a-bug/</feedburner:origLink></item>
		<item>
		<title>New Poll: What Do You Want To Read Here In 2009?</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/iTTGnnSdPA8/</link>
		<comments>http://davybrion.com/blog/2008/12/new-poll-what-do-you-want-to-read-here-in-2009/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 12:41:11 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[About The Blog]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=786</guid>
		<description><![CDATA[Well, 2008 is just about over, so i figured i&#8217;d ask you guys what kind of stuff you&#8217;d like to read on this blog in 2009.  The options (you can vote in the poll on the top right area of this page) are:

The same kind of topics as in 2008
More NHibernate related posts
Less NHibernate [...]]]></description>
			<content:encoded><![CDATA[<p>Well, 2008 is just about over, so i figured i&#8217;d ask you guys what kind of stuff you&#8217;d like to read on this blog in 2009.  The options (you can vote in the poll on the top right area of this page) are:</p>
<ul>
<li>The same kind of topics as in 2008</li>
<li>More NHibernate related posts</li>
<li>Less NHibernate related posts</li>
<li>More introductory posts to various topics</li>
<li>More real world examples, problems and situations</li>
<li>More opinion posts</li>
<li>Less opinion posts</li>
<li>More information about NHibernate&#8217;s development</li>
</ul>
<p>You can select up to 4 items if you want.  I won&#8217;t promise anything, but i will try to keep the outcome of the vote into account <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Any other suggestions or comments about what kind of stuff i should be writing about are always welcome of course.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=New%20Poll%3A%20What%20Do%20You%20Want%20To%20Read%20Here%20In%202009%3F&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fnew-poll-what-do-you-want-to-read-here-in-2009%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/Om9hrAqeF2JXnugvABfDqPVnDIg/a"><img src="http://feedads.googleadservices.com/~a/Om9hrAqeF2JXnugvABfDqPVnDIg/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/iTTGnnSdPA8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/new-poll-what-do-you-want-to-read-here-in-2009/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/new-poll-what-do-you-want-to-read-here-in-2009/</feedburner:origLink></item>
		<item>
		<title>What Would You Choose For New .NET Web Development?</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/LnhEpsOjksw/</link>
		<comments>http://davybrion.com/blog/2008/12/what-would-you-choose-for-new-dotnetweb-development/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 11:24:34 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=756</guid>
		<description><![CDATA[Web development in the .NET world has gotten a lot more interesting in the last couple of years.  A few years ago, the only choice we had for a web front-end was ASP.NET WebForms.  Nowadays you can add ASP.NET MVC and Silverlight to the mix.  Obviously each option has its pro&#8217;s and [...]]]></description>
			<content:encoded><![CDATA[<p>Web development in the .NET world has gotten a lot more interesting in the last couple of years.  A few years ago, the only choice we had for a web front-end was ASP.NET WebForms.  Nowadays you can add ASP.NET MVC and Silverlight to the mix.  Obviously each option has its pro&#8217;s and con&#8217;s, so it&#8217;s not always clear which option should be used when you&#8217;re starting to build a new Web application.</p>
<p>Let&#8217;s start with ASP.NET WebForms.  This is the option that has been available since the .NET platform was introduced, so there are already a lot of people experienced with it.  There is also a ton of information available about the ins and outs of WebForms.  And when it comes to commercial tool vendor support, it&#8217;s clearly miles ahead of the other options since there are lots of commercially supported controls available for it.  Unfortunately, WebForms was originally created to offer a similar development model to WinForms developers.  The code-behind files and the event-driven way of working is very similar to how you would write code in WinForms applications.  Obviously, web applications and windows applications are completely different things, so you can&#8217;t reasonably expect the same way of working to be suitable for both.</p>
<p>Particularly, the Page and Control lifecycles are rather complex (at least much more complex than i would think they&#8217;d need to be) and often cause weird issues on complex pages.  The event-driven model of both the Page class and the Control class (and its derivatives) seem to be the major cause of this.  I think most WebForms developers have on more than one occasion spent long times debugging weird situations which were ultimately related to certain events triggering unexpected behavior in other controls on the same page.  Granted, people with an in-depth knowledge of how these lifecycles really work don&#8217;t run into this as much, or are capable of avoiding these problems altogether. </p>
<p>You could indeed make the argument that most of the problems that people are experiencing with WebForms are caused by those people&#8217;s lack of understanding how it really works and how it really should be done.   On the other hand, that is a pretty good sign that WebForms development isn&#8217;t intuitive or clear enough, and that while Microsoft has tried hard to make it easy to use,  most people seem to solve their WebForms problems by hacking around their problems, or playing around with settings until it seems to work. </p>
<p>Another major problem with WebForms is that it doesn&#8217;t easily enable Test Driven Development.  True, there are various patterns you can use to make sure you can write testable UI logic (up to a certain point anyway) but all in all, these approaches require more effort than should be necessary and you often end up wrapping a lot of stuff just to be able to test it.  WebForms in general was never designed with testability in mind, and you will most definitely be confronted with that if you try to write testable UI code with WebForms.</p>
<p>As you can probably tell, i&#8217;m not a huge fan of WebForms.  I think it&#8217;s fine for simple applications, but for anything beyond that i&#8217;d like to avoid it as much as possible.</p>
<p>Microsoft&#8217;s upcoming ASP.NET MVC framework aims to fix much of the issues i&#8217;ve mentioned above.  It was designed with testability in mind, and although it&#8217;s not perfect either (depending on who you ask), it is certainly a huge improvement over WebForms when it comes to writing testable UI code.  You also have a lot more options when it comes to having the framework behave the way you&#8217;d like it to.  Another important benefit is the fact that ASP.NET MVC kinda forces you to structure your code in a much more sane manner.  You put as little logic as possible in the views, and you put most of it in the Controllers where it belongs.  Obviously, that doesn&#8217;t mean you should put business logic in the Controllers!  </p>
<p>One of the downsides of ASP.NET MVC is that, due to its completely different way of working compared to WebForms, it comes with a much higher learning curve.  Experienced WebForms developers might struggle with it at first, and might even be frustrated because most of their hard-earned WebForms experience no longer gives them a benefit.  Some will probably enjoy it much more than WebForms, and some will probably dislike it strongly because it&#8217;s so different.   Another downside is that there are far less commercial tool vendors that are offering ASP.NET MVC controls, at least compared to WebForms.  Although that might not be that big of an issue, since i suspect that it&#8217;s easier to develop nice looking and reusable controls yourself when using ASP.NET MVC than it is to do so when using WebForms.</p>
<p>If you&#8217;re starting out with ASP.NET MVC, i think it&#8217;s safe to assume that you won&#8217;t proceed as quickly as you&#8217;re used to at first.  But once you&#8217;re used to the new way of working, i&#8217;m pretty sure that it enables you to rapidly implement new pages and new functionality in a very clean way.  For true web applications, i would probably pick ASP.NET MVC everytime, unless you don&#8217;t have the room to get over the learning curve.  Also, when combined with a client-side javascript library like JQuery, this approach seems very compelling.  Yes, i know you can use JQuery with WebForms as well, but it just seems to lend itself better to the MVC approach.</p>
<p>And then there&#8217;s Silverlight.  There are already a couple of reasons why people would not want to use Silverlight for web applications.  For starters, even though the application is running in a browser, it&#8217;s not really a true web application is it?  Your users can&#8217;t bookmark pages, using the back button leads to unexpected behavior, there aren&#8217;t that many options for Search Engine Optimization, etc&#8230; However, if your only web-related requirement is that your application needs to run in a browser, without having to worry about any of the typical expected requirements for web applications, then Silverlight is a pretty interesting choice as well.  You can very easily create very rich applications, with possibilities that are either impossible, or extremely difficult to do with typical web development platforms.</p>
<p>Our <a href="http://davybrion.com/blog/2008/11/genesis-bridging-the-gap-between-requirement-and-code/">Genesis</a> web front-end is developed in Silverlight.  The UI not only looks great, but you can navigate between all of the available data in a manner that is simply much easier to develop than it would be for typical web apps.  It&#8217;s very easy to create that &#8216;wow&#8217;-effect with your users in Silverlight.  Obviously, that &#8216;wow&#8217;-effect isn&#8217;t the most important part of your application, but it does count for something.</p>
<p>Another interesting aspect of Silverlight development is that you can go back to a more statefull development model compared to the typically stateless nature of web aplications.  After all, the cost of that state is no longer something your web server has to bear.  It&#8217;s now the client who has to keep that state around, so you can avoid a few extra roundtrips here and there as well.  Then again, you really don&#8217;t want your Silverlight application using huge amounts of RAM in your user&#8217;s browser either so you do need to take care not to go overboard with it. The development model is completely different than both WebForms and ASP.NET MVC, but if you already have people with WPF experience the learning curve is probably not that high.  </p>
<p>However, testability isn&#8217;t great (yet) when it comes to Silverlight.  It&#8217;s possible to write testable code, and you can execute tests in the Silverlight runtime, but it doesn&#8217;t really lend itself to a true TDD approach yet although i hope that will improve in the future.  </p>
<p>So there you have it&#8230; the three options for .NET web development.  I&#8217;d stay away from WebForms altogether from now on, and i&#8217;d decide between ASP.NET MVC and Silverlight on a case by case basis.  What, you weren&#8217;t hoping for a definitive answer were you? <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I would be interested in hearing your thoughts about pro&#8217;s and con&#8217;s of any of the options&#8230; particularly things that i haven&#8217;t mentioned, or if you just plain disagree with my statements.  Which option would you prefer to use, or not to use? </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=What%20Would%20You%20Choose%20For%20New%20.NET%20Web%20Development%3F&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fwhat-would-you-choose-for-new-dotnetweb-development%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/-ukvf6FUgdby7QspO3jcm-KaFHQ/a"><img src="http://feedads.googleadservices.com/~a/-ukvf6FUgdby7QspO3jcm-KaFHQ/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/LnhEpsOjksw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/what-would-you-choose-for-new-dotnetweb-development/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/what-would-you-choose-for-new-dotnetweb-development/</feedburner:origLink></item>
		<item>
		<title>Junior Vs Senior Developers?</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/bLq66DDLqyw/</link>
		<comments>http://davybrion.com/blog/2008/12/junior-vs-senior-developers/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 00:31:00 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Opinions]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=777</guid>
		<description><![CDATA[Chris Brandsma recently wrote an insightful post about how we shouldn&#8217;t coddle junior developers.  It&#8217;s a good post and i can definitely understand Chris&#8217; frustrations on the matter.   There&#8217;s just one thing i don&#8217;t understand though: why do we even differentiate between junior and senior developers?
First of all, what&#8217;s the difference between [...]]]></description>
			<content:encoded><![CDATA[<p>Chris Brandsma recently wrote an insightful <a href="http://elegantcode.com/2008/12/27/thinking-only-of-the-junior-developer/">post</a> about how we shouldn&#8217;t coddle junior developers.  It&#8217;s a good post and i can definitely understand Chris&#8217; frustrations on the matter.   There&#8217;s just one thing i don&#8217;t understand though: why do we even differentiate between junior and senior developers?</p>
<p>First of all, what&#8217;s the difference between a senior developer and a junior developer? Is it merely the number of years of experience? In previous client engagements, i&#8217;ve seen more than my share of bad developers who&#8217;ve had years and years of experience.  Would i trust those developers more simply because they have the experience required to be called &#8217;seniors&#8217;?  Hell no.  Trust has to be earned, i don&#8217;t care if you just graduated or if you&#8217;ve been writing code for 5 years or more. </p>
<p>When i have to work with someone i&#8217;ve never worked before, i assess this person&#8217;s qualities and capabilities on two things: how he <strong>thinks</strong> about writing code (in general), and how easy he can pick up new concepts/practices/principles.  That&#8217;s it.   A junior developer with little to no experience can often be a lot more valuable than a developer who has 5 years of experience under his belt and just assumes that he knows it all.</p>
<p>With a senior developer, you have to be lucky that he&#8217;s learned from his previous mistakes (and <strong>every</strong> developer makes mistakes, no matter how good he is or how much experience he has), that he hasn&#8217;t picked up too many bad habits and that he is open minded.  If you can get a senior developer like that, consider yourself very, very lucky because there really aren&#8217;t that many of them.</p>
<p>With a junior developer, you can easily mold them into the kind of developer you want them to be.  They haven&#8217;t really had a lot of time to pick up bad habits, and they are eager to prove that they belong at your company so they will be very eager to learn and improve.  All you need is a couple of people who are willing and capable of teaching these young developers.</p>
<p>Of course, with junior developers you do have to live with the fact that they will make rookie mistakes.  You have to review their work a bit more, and make sure that they learn from their mistakes.  If you do this from the beginning, you&#8217;ll quickly notice that the extra reviewing tasks will soon take up less and less work.  </p>
<p>At my <a href="http://www.itemsolutions.com/home">company</a>, we don&#8217;t really differentiate between juniors and seniors.  The last couple of years, we&#8217;ve pretty much only hired young developers who just graduated.  And so far, it&#8217;s worked out great.  They never get assigned easier tasks or anything like that, and they have to do the same kind of stuff that people with more experience need to do.  The result is that we have a bunch of young developers (i think the average age of our developers is 24 or something) who already do a great job, and they&#8217;re constantly getting better.  </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=Junior%20Vs%20Senior%20Developers%3F&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fjunior-vs-senior-developers%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/07dNwJHKVGNIdwqYGM3CV4Pi3Xw/a"><img src="http://feedads.googleadservices.com/~a/07dNwJHKVGNIdwqYGM3CV4Pi3Xw/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/bLq66DDLqyw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/junior-vs-senior-developers/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/junior-vs-senior-developers/</feedburner:origLink></item>
		<item>
		<title>Tired Of Working With Big Visual Studio Solutions?</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/TiVek1ukmf0/</link>
		<comments>http://davybrion.com/blog/2008/12/tired-of-working-with-big-visual-studio-solutions/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 00:27:07 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=767</guid>
		<description><![CDATA[Ever noticed how Visual Studio can be painfully slow when it comes to working with big solutions? It starts using large amounts of RAM, building the project takes way too long, and with practically every change you make it has to rebuild a lot of the projects in the solution which can waste a tremendous [...]]]></description>
			<content:encoded><![CDATA[<p>Ever noticed how Visual Studio can be painfully slow when it comes to working with big solutions? It starts using large amounts of RAM, building the project takes way too long, and with practically every change you make it has to rebuild a lot of the projects in the solution which can waste a tremendous amount of time if you add it all up.</p>
<p>Consider the following solution:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2008/12/full_solution_tree.png" alt="full_solution_tree" title="full_solution_tree" width="238" height="344" /></p>
<p>Now, i&#8217;m not going to get into the specifics of each project in this solution&#8230; most of these projects were created before i ever got involved with this project, and i&#8217;m not really happy with the entire structure.  It&#8217;s a pretty big application, and a while ago we decided to move to a new architecture.  But since we can&#8217;t just rewrite the whole thing, we put the new stuff (using the new architecture) in the same application and we&#8217;re going to gradually rewrite the old parts using the new architecture.  </p>
<p>I wanted to keep the new stuff completely separated from the old stuff, so i added more projects to it (the EMS.* projects).  Before i added the new projects to the solution, it was already painfully slow to use this solution with Visual Studio.  After adding the new projects, it obviously only got worse.  Since we&#8217;re spending most of our development work in the new projects, i wanted to see if i could simply create a new solution which would contain only the projects we usually need.  That new solution looks like this:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2008/12/smaller_solution_tree.png" alt="smaller_solution_tree" title="smaller_solution_tree" width="267" height="131"  /></p>
<p>Much better&#8230;. but now you&#8217;re probably thinking: doesn&#8217;t CMS.WebApplication reference any of the other projects? It does reference a few of them actually:</p>
<p><img src="http://davybrion.com/blog/wp-content/uploads/2008/12/dependencies.png" alt="dependencies" title="dependencies" width="165" height="134" /></p>
<p>Visual Studio indicates that it can&#8217;t resolve these references.  So this new solution isn&#8217;t usable, right? Well, it is actually.  You just have to make sure that you&#8217;ve done a full build of the entire solution (the one that has all of the projects in it) before you build the small one.  If you use the small solution after you&#8217;ve built the big one, Visual Studio is smart enough to remember where it got those compiled dependencies from in the first place.</p>
<p>So is this really usable? It sure is&#8230; we do most of our work in the smaller solution, and we can modify and recompile as much as we want without problems and without wasting huge amounts of time just waiting for Visual Studio and the compiler.  The only issue we have with this approach is when we need to make changes in some of the older projects that aren&#8217;t in the small solution.  Whenever someone makes a change there that requires a recompile of the CMS.WebApplication project, every teammember needs to recompile the entire big solution.  But to avoid having to load the entire solution in Visual Studio, you can just run the following command in a Visual Studio 2008 Command Prompt:</p>
<p><code><br />
msbuild ems.sln<br />
</code></p>
<p>and it builds the entire solution without using Visual Studio.  After that, your smaller solution will work again.</p>
<p>If you&#8217;re working with big Visual Studio solutions and the slowness of this bothers you, be sure to give this a shot.  You can create as many of these small solutions as you like, depending on which parts of the codebase you typically need to work with.  It can easily save you a lot of time, and avoid unnecessary frustration as well <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>For new solutions, i think it&#8217;s better to just keep the number of projects to a minimum which i&#8217;ve explained previously <a href="http://davybrion.com/blog/2008/07/many-projects-dont-lead-to-a-good-solution/">here</a></p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fdavybrion.com%2fblog%2f2008%2f12%2ftired-of-working-with-big-visual-studio-solutions%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fdavybrion.com%2fblog%2f2008%2f12%2ftired-of-working-with-big-visual-studio-solutions%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=Tired%20Of%20Working%20With%20Big%20Visual%20Studio%20Solutions%3F&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Ftired-of-working-with-big-visual-studio-solutions%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/amTscJcJejw5OBpJ_wDZf0kpKKg/a"><img src="http://feedads.googleadservices.com/~a/amTscJcJejw5OBpJ_wDZf0kpKKg/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/TiVek1ukmf0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/tired-of-working-with-big-visual-studio-solutions/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/tired-of-working-with-big-visual-studio-solutions/</feedburner:origLink></item>
		<item>
		<title>It Was A Pretty Good Year</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/Uv2bx_s9ge0/</link>
		<comments>http://davybrion.com/blog/2008/12/it-was-a-pretty-good-year/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 13:47:21 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=763</guid>
		<description><![CDATA[2008 was a pretty good year for the .NET world.  We&#8217;ve seen a pretty big rise in people&#8217;s interest, understanding and accepting of Object Relational Mapping, Inversion Of Control containers, writing testable code and separation of concerns.  Those aren&#8217;t the only things that have improved in the .NET world this year, but i [...]]]></description>
			<content:encoded><![CDATA[<p>2008 was a pretty good year for the .NET world.  We&#8217;ve seen a pretty big rise in people&#8217;s interest, understanding and accepting of Object Relational Mapping, Inversion Of Control containers, writing testable code and separation of concerns.  Those aren&#8217;t the only things that have improved in the .NET world this year, but i think those are the most important improvements we&#8217;ve seen from the developer community.  </p>
<p>I&#8217;m also pretty happy with the way Microsoft is starting to open up the development of some of their projects, with ASP.NET MVC being a very nice example.  They&#8217;re not doing true open source development yet, but at least they are listening to the community more and more.  I&#8217;m especially happy with how people like <a href="http://www.hanselman.com/blog/">Scott Hanselman</a>, <a href="http://haacked.com/">Phil Haack</a>, and <a href="http://codebetter.com/blogs/glenn.block/">Glenn Block</a> not only deal with the community, but are active (and positive) participants of it.  Then again, there are definitely things that should&#8217;ve been handled better (Entity Framework, Oxite, LINQ To SQL&#8217;s future, &#8230;).  Hopefully, we&#8217;ll get to see a lot less of those kind of mistakes in 2009.  But all in all i think it&#8217;s been a rather impressive year from Microsoft&#8217;s Developer Division. </p>
<p>2008 has been pretty good for myself as well.  I escaped from working in Enterprise Hell and now get to do a lot of interesting things at work with motivated and talented co-workers.  I&#8217;ve also seen my subscriber count go from 40 to around 700 (on average) this year, which certainly provides a lot of motivation to keep going.  I also joined some great bloggers at ElegantCode.com, and joined the NHibernate developers.   Should keep me pretty busy in 2009 <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m taking a few days off from blogging, so happy newyear everyone, and i&#8217;ll see you all early January <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=It%20Was%20A%20Pretty%20Good%20Year&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fit-was-a-pretty-good-year%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/v5owsx32V7imyV2KfvcL8B6nbJ0/a"><img src="http://feedads.googleadservices.com/~a/v5owsx32V7imyV2KfvcL8B6nbJ0/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/Uv2bx_s9ge0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/it-was-a-pretty-good-year/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/it-was-a-pretty-good-year/</feedburner:origLink></item>
		<item>
		<title>Gotta Love A Clean Development Environment</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/pDz5kSp58P8/</link>
		<comments>http://davybrion.com/blog/2008/12/gotta-love-a-clean-development-environment/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 00:34:34 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=749</guid>
		<description><![CDATA[Just installed a new development system for personal use&#8230; currently i only have the following installed:

Windows XP Professional, with Service Pack 3: i don&#8217;t have Windows 2008 and i still don&#8217;t consider Vista to be a valid option
SQL Server 2005 Developer Edition: i don&#8217;t have the 2008 version, plus the 2005 version more than suits [...]]]></description>
			<content:encoded><![CDATA[<p>Just installed a new development system for personal use&#8230; currently i only have the following installed:</p>
<ul>
<li>Windows XP Professional, with Service Pack 3: i don&#8217;t have Windows 2008 and i still don&#8217;t consider Vista to be a valid option</li>
<li>SQL Server 2005 Developer Edition: i don&#8217;t have the 2008 version, plus the 2005 version more than suits my needs</li>
<li>Visual Studio 2008 with Service Pack 1: duh&#8230;.</li>
<li>Resharper 4.1: duh&#8230; won&#8217;t use Visual Studio without it</li>
<li>TortoiseSVN + VisualSVN: TortoiseSVN is great already, but the Visual Studio integration that VisualSVN provides is so nice that i can&#8217;t go back to just using TortoiseSVN.</li>
<li>NHibernate Profiler: it&#8217;s not even out of private beta and i already consider this a must-have tool&#8230; i hope Ayende is gonna go easy on the licensing cost for this <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>dotTrace: you gotta have a profiler, right?</li>
</ul>
<p>Anything else i should consider installing?  I only use this system for development so i don&#8217;t want any suggestions that aren&#8217;t related to that.</p>
<p>On a side note, despite being a Parallels customer i set this system up in VMWare Fusion.  According to some reviews i read, Fusion beats Parallels when it comes to IO, making the system feel more &#8217;snappy&#8217;.  I&#8217;ve been very impressed with the Fusion performance already so i just bought a license and am planning to use Fusion exclusively from now on instead of Parallels. </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=Gotta%20Love%20A%20Clean%20Development%20Environment&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fgotta-love-a-clean-development-environment%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/5Hyl2_Bpy1nqg45j4ydjQPlu_Rk/a"><img src="http://feedads.googleadservices.com/~a/5Hyl2_Bpy1nqg45j4ydjQPlu_Rk/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/pDz5kSp58P8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/gotta-love-a-clean-development-environment/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/gotta-love-a-clean-development-environment/</feedburner:origLink></item>
		<item>
		<title>The Unrealistic Deadline Anti-Pattern</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/WvAvrP-xgQ0/</link>
		<comments>http://davybrion.com/blog/2008/12/the-unrealistic-deadline-anti-pattern/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 12:29:33 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=744</guid>
		<description><![CDATA[I just read this post from Mohammad Azam about a project that was impossible to do using Agile practices.
I quote:
A reasonable deadline for the project was approximately 3 months but it had to be completed in a month. At this time an agile book will indicate that the developer should talk to the owner and [...]]]></description>
			<content:encoded><![CDATA[<p>I just read this <a href="http://www.azamsharp.com//Posts/145_When_Being_Agile_Kills_the_Project.aspx">post</a> from <a href="http://www.azamsharp.com/">Mohammad Azam</a> about a project that was impossible to do using Agile practices.</p>
<p>I quote:</p>
<blockquote><p>A reasonable deadline for the project was approximately 3 months but it had to be completed in a month. At this time an agile book will indicate that the developer should talk to the owner and come to a reasonable deadline. Unfortunately, in this case the owner was fixed with the deadline and was not willing to move it further.</p></blockquote>
<p>The author further concludes that following the agile principles would have killed the project.  He dropped some of the agile principles and practices, and finished the project in 29 days.  </p>
<blockquote><p>Yes, the resultant code was messy but at the end I get to keep my job.</p></blockquote>
<p>I have no problem with Mohammad dropping agile practices/principles in order to complete this on time and to help him keep his job (especially in the current economy).  I do have a problem with the idea that &#8216;Agile&#8217; can kill a project.  The only thing that killed this project is the unrealistic deadline which was set by the owner.  The fact that the project was delivered within the requested time frame, and even assuming that it is completely satisfactory to the owner, does not mean that it was a good idea to hold this project to a deadline which only allowed for one third of the estimated workload.</p>
<p>Now some of you are probably thinking &#8220;the deadline couldn&#8217;t have killed the project since it was delivered within that deadline!&#8221;.  True, to a point.  We all know what happens when developers face tight deadlines: they take technical shortcuts and they accumulate technical debt.  Mohammad already stated that the resulting code was messy so i guess it&#8217;s safe to assume there&#8217;s quite a bit of technical debt there.  Being in technical debt is like owing money to Tony Soprano&#8230; you better get out of debt <strong>fast</strong> or things are gonna get <strong>much worse, very soon even</strong>.  The longer you wait with paying off the debt, the more you&#8217;ll lose certain abilities and possibilities.</p>
<p>Getting out of technical debt can be pretty expensive, but there&#8217;s not really an alternative.  If you don&#8217;t get out of debt, further maintenance of the code base and adding new features will only become more expensive over time.  Failure to pay off the debt will sooner or later kill the project entirely because the gains that the project brings are no longer greater than the costs that come with it.  At that point, the decision is often made to build a new system to replace the old one.  The new one is gonna fix all of the problems of the old one.  And if you&#8217;re lucky, the managers will have figured out by then that unrealistic deadlines only cost more money in the long term than a reasonable deadline would have. </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=The%20Unrealistic%20Deadline%20Anti-Pattern&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fthe-unrealistic-deadline-anti-pattern%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/z5NZ94aI_H4XrniGhsDeWINCkuA/a"><img src="http://feedads.googleadservices.com/~a/z5NZ94aI_H4XrniGhsDeWINCkuA/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/WvAvrP-xgQ0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/the-unrealistic-deadline-anti-pattern/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/the-unrealistic-deadline-anti-pattern/</feedburner:origLink></item>
		<item>
		<title>Favorite Operating System For Development?</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/5lOExNGL1vw/</link>
		<comments>http://davybrion.com/blog/2008/12/favorite-operating-system-for-development/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 18:42:08 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=741</guid>
		<description><![CDATA[With the recent news that the cutoff date for Windows XP has been extended by a few more months, i was wondering which operating system you guys prefer for development.  So i&#8217;ve added a poll to the site (it&#8217;s on the right top of the page) where you can cast your vote.
I have to [...]]]></description>
			<content:encoded><![CDATA[<p>With the recent <a href="http://www.informationweek.com/news/windows/operatingsystems/showArticle.jhtml?articleID=212501654&#038;subSection=All+Stories">news</a> that the cutoff date for Windows XP has been extended by a few more months, i was wondering which operating system you guys prefer for development.  So i&#8217;ve added a poll to the site (it&#8217;s on the right top of the page) where you can cast your vote.</p>
<p>I have to admit that i still prefer Windows XP, probably because it&#8217;s the lightest one of them all at the moment, and since i run XP in a Parallels VM on a cheap Macbook, that kinda matters <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>At work, i&#8217;m using Windows Vista&#8230; not really happy with it though&#8230;</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=Favorite%20Operating%20System%20For%20Development%3F&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Ffavorite-operating-system-for-development%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/vBSXCiW1WjBU9ZiqsHijyyJqA7I/a"><img src="http://feedads.googleadservices.com/~a/vBSXCiW1WjBU9ZiqsHijyyJqA7I/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/5lOExNGL1vw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/favorite-operating-system-for-development/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/favorite-operating-system-for-development/</feedburner:origLink></item>
		<item>
		<title>The Resolvable</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/caVdqYS8qXA/</link>
		<comments>http://davybrion.com/blog/2008/12/the-resolvable/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 14:48:26 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Castle Windsor]]></category>

		<category><![CDATA[Memory Management]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=737</guid>
		<description><![CDATA[I wrote a post last week about a memory leak i had introduced in my code due to not properly releasing resolved components through the Windsor IoC container.  I wanted to try to make sure that i&#8217;d never make that mistake again and this is the approach i came up with.
If you&#8217;re using an [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a post last week about a memory leak i had introduced in my code due to <a href="http://davybrion.com/blog/2008/12/the-importance-of-releasing-your-components-through-windsor/">not properly releasing resolved components through the Windsor IoC container</a>.  I wanted to try to make sure that i&#8217;d never make that mistake again and this is the approach i came up with.</p>
<p>If you&#8217;re using an IOC container it&#8217;s important to not use it all over the place.  You basically use it in as few places as possible to resolve a component and you let the container sort out all of the dependencies.  So in the few places where you use the container directly, you need to resolve the component, and in case of transient components you also need to release them through the container.  Releasing it is very easy to forget, so i wanted something that would guarantee that the component would be properly released.  Enter the Resolvable class:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Resolvable</span>&lt;T&gt; : <span style="color: #2b91af;">Disposable</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">readonly</span> T instance;</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> Resolvable() : <span style="color: blue;">this</span>(<span style="color: blue;">null</span>) {}</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> Resolvable(<span style="color: blue;">object</span> argumentsAsAnonymousType)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (argumentsAsAnonymousType == <span style="color: blue;">null</span>)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; instance = <span style="color: #2b91af;">IoC</span>.Container.Resolve&lt;T&gt;();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">else</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; instance = <span style="color: #2b91af;">IoC</span>.Container.Resolve&lt;T&gt;(argumentsAsAnonymousType);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> T Instance</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">get</span> { <span style="color: blue;">return</span> instance; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">override</span> <span style="color: blue;">void</span> DisposeManagedResources()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IoC</span>.Container.Release(instance);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code> </p>
<p>The Resolvable class inherits from my <a href="http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/">Disposable class</a>, so the Disposable pattern is correctly implemented.</p>
<p>From now on, instead of calling the container directly, i just instantiate a new Resolvable in a using block.  Let&#8217;s try it out.</p>
<p>I&#8217;m reusing my test component with a dependency from one of the previous posts:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IDependency</span> : <span style="color: #2b91af;">IDisposable</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">MyDependency</span> : <span style="color: #2b91af;">IDependency</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Disposed = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IController</span> : <span style="color: #2b91af;">IDisposable</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IDependency</span> Dependency { <span style="color: blue;">get</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Controller</span> : <span style="color: #2b91af;">IController</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">IDependency</span> Dependency { <span style="color: blue;">get</span>; <span style="color: blue;">private</span> <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> Controller(<span style="color: #2b91af;">IDependency</span> myDependency)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dependency = myDependency;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dependency.Dispose();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Disposed = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>Now, instead of resolving an IController directly through the container and having to dispose of it, i just do this:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> ResolvableInstanceIsProperlyReleasedAfterDisposal()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IoC</span>.Container.Register(<span style="color: #2b91af;">Component</span>.For&lt;<span style="color: #2b91af;">IController</span>&gt;().ImplementedBy&lt;<span style="color: #2b91af;">Controller</span>&gt;().LifeStyle.Transient);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IoC</span>.Container.Register(<span style="color: #2b91af;">Component</span>.For&lt;<span style="color: #2b91af;">IDependency</span>&gt;().ImplementedBy&lt;<span style="color: #2b91af;">MyDependency</span>&gt;().LifeStyle.Transient);</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IController</span> controller;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IDependency</span> dependency;</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">using</span> (<span style="color: blue;">var</span> resolvable = <span style="color: blue;">new</span> <span style="color: #2b91af;">Resolvable</span>&lt;<span style="color: #2b91af;">IController</span>&gt;())</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; controller = resolvable.Instance;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dependency = controller.Dependency;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsTrue(controller.Disposed);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsTrue(dependency.Disposed);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(<span style="color: #2b91af;">IoC</span>.Container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(<span style="color: #2b91af;">IoC</span>.Container.Kernel.ReleasePolicy.HasTrack(dependency));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>The container doesn&#8217;t hold the reference to the instance, and both the instance and its dependency is properly disposed. </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=The%20Resolvable&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fthe-resolvable%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/rh3sphsUIoZq5Ul8-qtR8ecITz4/a"><img src="http://feedads.googleadservices.com/~a/rh3sphsUIoZq5Ul8-qtR8ecITz4/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/caVdqYS8qXA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/the-resolvable/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/the-resolvable/</feedburner:origLink></item>
		<item>
		<title>Is This A Good Approach For Multi-Tenancy Or Not?</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/YeiMc_cXr98/</link>
		<comments>http://davybrion.com/blog/2008/12/is-this-a-good-approach-for-multi-tenancy-or-not/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 20:42:35 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=730</guid>
		<description><![CDATA[Here&#8217;s the situation: we have an application which is used by multiple customers.  The application consists of various functional modules.  Each customer can use one or many (or obviously all) of these modules.  In the past we used to deploy this application for each customer.   The configuration file contained various [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the situation: we have an application which is used by multiple customers.  The application consists of various functional modules.  Each customer can use one or many (or obviously all) of these modules.  In the past we used to deploy this application for each customer.   The configuration file contained various settings that could differ from customer to customer and obviously, each deployed version had its specific configuration file depending on the settings required for each customer.  This approach worked, but it was not really ideal.</p>
<p>Multi-tenancy to the rescue! Not sure if this counts as the official definition of multi-tenancy, but wikipedia defines it likes this:</p>
<blockquote><p>
Multitenancy refers to a principle in software architecture where a single instance of the software runs on a software-as-a-service (SaaS) vendor&#8217;s servers, serving multiple client organizations (tenants). Multitenancy is contrasted with a multi-instance architecture where separate software instances (or hardware systems) are set up for different client organizations. With a multitenant architecture, a software application is designed to virtually partition its data and configuration so that each client organization works with a customized virtual application instance.
</p></blockquote>
<p>Sounds like this is exactly what we&#8217;re looking for.  So i&#8217;ve recently been working on changing the application to support this, and i came up with the approach i will outline in the rest of this post.  The approach does not strictly comply with the definition above, but it does seem to comply with <a href="http://ayende.com/Blog/archive/2008/08/06/Multi-Tenancy.aspx">Ayende&#8217;s definition</a> of it.  I&#8217;d like to get some feedback from you guys as to whether you believe this approach is good or not, what could be better, what we need to keep in mind, etc&#8230;</p>
<p>First of all, i would like to point out that this application already exists.  We already have a database with about 200 tables in it and there are about 150 pages (it&#8217;s a web app obviously).  So obviously, we can&#8217;t just change everything to make it fully compliant with &#8216;the definition&#8217;.</p>
<p>Let&#8217;s start with the database.  Instead of trying to use one huge database to keep all of the tenants&#8217; data, which would require modifications in a large amount of the existing tables, we&#8217;ve decided to go with a separate database for each tenant.  Each database will have an identical structure, regardless of whether some functional modules are used or not by a particular tenant.  There is also one &#8216;master&#8217; database which contains tenant-specific data.  Basically it contains all of the configuration settings for each tenant, including connection strings to each tenants&#8217; specific database.  The connection strings do not contain user names and passwords as we will use Windows&#8217; Integrated Security to connect to the specific databases (more on that in a bit).</p>
<p>Now for the application itself.  Our first idea was to have one actual instance of the application, and the application would be able to determine the current tenant for each request based on the URL of the incoming request.  Tenant A would have an URL like tenanta.ourproduct.com, tenant B would have tenantb.ourproduct.com etc.  The application would basically use the URL to get the correct tenant-info from the master database (note that the connection string to the master database would be the only connection string we&#8217;d have in the application&#8217;s configuration file) and it would then use the tenant-specific database for each request with the tenant&#8217;s application URL.</p>
<p>The idea was to use an NHibernate SessionFactory for each specific tenant.  You obviously can&#8217;t use just one because you&#8217;re using multiple databases.  But we also use NHibernate&#8217;s 2nd Level Cache, which is problematic when you&#8217;re using multiple SessionFactories.  The 2nd Level Cache is great, but it doesn&#8217;t differentiate between multiple SessionFactories.  So if you have the result of a specific query cached, you could get that data back for a different tenant than the one the data actually belongs to if the query&#8217;s parameters happen to be identical.  Btw, if i&#8217;m wrong about this please let me know.</p>
<p>So then we figured we could still use one physical deployment (as in: one physical folder where the application is located), and then we&#8217;d use multiple virtual directories in IIS which all point to the same physical folder.  We&#8217;d basically have one virtual directory (and one instance of the application) per tenant.  We still have the benefit of one physical deployment, and because each tenant&#8217;s &#8216;virtual&#8217; application runs in its own AppDomain, the caching problem is no longer an issue.  Each virtual directory is configured for the URL of its tenant and the running instance of the application can still retrieve the actual tenant&#8217;s data from the master database based on the URL.  Each virtual directory can run in its own Application Pool which can be set up to run under a Windows account which is specific to the current tenant.  This allows us to use Integrated Security when connecting to the tenant-specific database.  So each tenant would only have access to the master database and its own specific database.  </p>
<p>Obviously, this approach would require a bit more effort in our &#8216;management module&#8217; (which is yet to be written).  Whenever we need to add a tenant, we not only have to create a specific database for the tenant, we&#8217;d also have to create a new windows account for the tenant, set up a new virtual directory, and an application pool if each tenant indeed runs in its own application pool under it&#8217;s own Windows account. </p>
<p>Apart from the management module, i&#8217;ve modified the application to work with this approach in just a few days work.  But, nothing is final just yet&#8230; so now i&#8217;d like to hear from you guys whether this is a good approach or not.  What are the possible problems we need to take into account?  Is this really still multi-tenancy?  I guess the opinions on this will be divided, but it does largely solve the issue of multiple deployment and multiple configuration files.  True, the configuration is now mostly in the master database and those settings need to be maintained as well.  However, they could now be maintained without having to redeploy the application which is a plus.  Some settings could even be modified by the tenant itself (at least, the users who have the proper privileges to do so).</p>
<p>So anyways, i&#8217;m awaiting your feedback <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>UPDATE: i&#8217;ve been told that i can simply use a different cache region for each tenant in NHibernate&#8217;s 2nd Level Cache&#8230; so i could avoid having to use multiple instances of the application.  Still not sure on whether one instance for all tenants would be better than one instance for each tenant though.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=Is%20This%20A%20Good%20Approach%20For%20Multi-Tenancy%20Or%20Not%3F&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fis-this-a-good-approach-for-multi-tenancy-or-not%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/V5AxehrZaql7aZUz3q2chd5Fusw/a"><img src="http://feedads.googleadservices.com/~a/V5AxehrZaql7aZUz3q2chd5Fusw/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/YeiMc_cXr98" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/is-this-a-good-approach-for-multi-tenancy-or-not/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/is-this-a-good-approach-for-multi-tenancy-or-not/</feedburner:origLink></item>
		<item>
		<title>The Component Burden</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/jbLtefBSOkI/</link>
		<comments>http://davybrion.com/blog/2008/12/the-component-burden/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 12:37:23 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Castle Windsor]]></category>

		<category><![CDATA[Memory Management]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=722</guid>
		<description><![CDATA[In my previous post i showed you how important it is to properly release the components you&#8217;ve resolved through the Windsor IoC container.  At the end of that post, i showed an example where a disposable dependency of a component had to be disposed by the component.  Basically something like this:


&#160;&#160;&#160; public class [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://davybrion.com/blog/2008/12/the-importance-of-releasing-your-components-through-windsor/">previous post</a> i showed you how important it is to properly release the components you&#8217;ve resolved through the Windsor IoC container.  At the end of that post, i showed an example where a disposable dependency of a component had to be disposed by the component.  Basically something like this:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Controller</span> : <span style="color: #2b91af;">IController</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">IDependency</span> Dependency { <span style="color: blue;">get</span>; <span style="color: blue;">private</span> <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> Controller(<span style="color: #2b91af;">IDependency</span> myDependency)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dependency = myDependency;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dependency.Dispose();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>This prompted the following <a href="http://elegantcode.com/2008/12/13/the-importance-of-releasing-your-components-through-windsor/#comment-39632">comment</a> by Bryan Watts:</p>
<blockquote><p>
So Controller is responsible for disposing of something it did not explicitly create? That’s a little presumptuous isn’t it?</p>
<blockquote><p>
> if you own a reference to an IDisposable instance, you are responsible for properly disposing of that instance.
</p></blockquote>
<p>I agree (and I’ve read your other article). However, in this case, Controller clearly does not own its dependency.
</p></blockquote>
<p>And Bryan is right.  For a lot of languages, memory management rules can be summarized (somewhat simplified) like this:</p>
<ul>
<li>If you create an instance of a class, you are responsible for releasing/freeing/disposing it.</li>
<li>If a factory creates an instance of a class, the factory is not responsible for releasing/freeing/disposing it.  This burden falls upon the object which requested the object from the factory</li>
<li>If you receive an instance of an object, you should not release/free/dispose it, unless you received the instance from a factory</li>
</ul>
<p>So where does this leave us with the example code shown above?  Clearly, we did not create the instance of the disposable dependency, so in theory, we are not allowed to dispose it.  Then again, if we weren&#8217;t using Dependency Injection we would have probably instantiated the disposable dependency in our constructor (or when we first need it).  In that case, we would have been responsible for disposing the disposable dependency.  </p>
<p>You could argue that the IoC container is in some way a factory which creates and supplies the dependency to our class.  So according to the rules stated above, it would be allowed to dispose the dependency.   The downside to this is that this means that our class (the Controller) has knowledge of the lifecycle of the dependency.  We know that the dependency has been configured with a Transient lifecycle (which means the container creates a new instance whenever an instance of its class is needed) so we can safely dispose it.  The problem is that this knowledge is implicit.  It is nowhere visible in the code of the Controller class.  The only place where this lifecycle is configured explicitly, is in the configuration of the IoC container so it would be wrong for the Controller to assume anything about the lifecycle of its dependencies.  </p>
<p>After all, suppose someone makes a change to the code of the dependency which makes it possible to be used with a different lifecycle.  Suppose someone makes the change to the dependency and then configures the IoC container to always return a singleton instance of this dependency.  If nobody thinks about the fact that the Controller still assumes a Transient lifecycle of the dependency, the disposal of the dependency will not be removed from the Controller class.  Once a Controller instance is created, and then disposed, it will try to dispose the instance of its dependency, which will cause problems because that instance is supposed to be used by other objects as well!</p>
<p>So what do we do? Do we dispose of the dependency in the Controller class because we know it&#8217;s safe (until someone changes the dependency and/or its configuration with the container)?  Or do we simply not dispose it (since we&#8217;re not really allowed to do so without some kind of implicit knowledge of the &#8216;outside world&#8217;)?</p>
<p>Neither option sounds very appealing.  The first option <strong>could</strong> lead to problems depending on possible future changes outside of the Controller class.  The second option <strong>is already problematic</strong> because a disposable dependency is not being disposed of as fast as it should be.  The disposal would basically be postponed until the instance is collected by the garbage collector.</p>
<p>Another alternative is to have the container inject a factory which can create transient instances of the dependency, instead of having the container inject the transient instance directly.  This would fix all of the discussed problems: the controller would not need to dispose the injected dependency, and can safely dispose the instantiated disposable instances.  However, having to create factories simply to avoid this problem seems a bit cumbersome.  The implementation of the factory could lead to other discussions as well because of how the factory should create the actual instance <strong>and its dependencies</strong>, which is exactly the reason why we wanted to use an IoC container in the first place.  True, the factory could resolve the instance directly through the IoC container, but then you&#8217;re just moving the problem to a different class without actually fixing it properly.</p>
<p>This entire problem has been described as the <a href="http://hammett.castleproject.org/?p=252">Component Burden</a> by Hammet, the original creator of the Windsor IoC container.  Obviously, this is something that the container should solve for us instead of us having to worry about it.  Ideally, the container would keep track of all of the disposable dependencies it has created to satisfy the creation of requested components.  Then when the requested component would be released, the container could safely dispose of each transient disposable dependency it created to create the requested component.  Luckily, the Castle developers have implemented this behavior <a href="http://www.nabble.com/Component-burden-impl-committed-td19848831.html">recently</a>, so if you&#8217;re using a recent build of the Windsor IoC container,  this problem should no longer occur and you shouldn&#8217;t be forced to dispose of dependencies that were injected into your objects. </p>
<p>The reason why i&#8217;m not using it yet is because there were many attempts at implementing this, and most attempts had considerable downsides to them.  This one has been committed to the trunk, so it&#8217;s probably a good solution, but i&#8217;m not going to use this solution in production systems until it has had some more time to prove itself.  So for now, i&#8217;m sticking with my approach where i manually dispose the injected dependencies.  I know it&#8217;s not the best approach, but until the real solution in the container is somewhat more proven to work without downsides, manually disposing the dependencies seems to be the lesser of multiple evils.</p>
<p>Keep in mind that i&#8217;m only talking about the Windsor IoC container.  I have no experience with StructureMap, NInject or Unity, so i have no idea how these containers deal with this problems.  If anyone with knowledge about these container could shed some light on how they deal with this, i&#8217;d be very interested in reading it <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=The%20Component%20Burden&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fthe-component-burden%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/ylnvTRQwjw2Jh-BxzqeahKh6g8M/a"><img src="http://feedads.googleadservices.com/~a/ylnvTRQwjw2Jh-BxzqeahKh6g8M/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/jbLtefBSOkI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/the-component-burden/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/the-component-burden/</feedburner:origLink></item>
		<item>
		<title>The Importance Of Releasing Your Components Through Windsor</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/7k1KQzPJouM/</link>
		<comments>http://davybrion.com/blog/2008/12/the-importance-of-releasing-your-components-through-windsor/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 14:12:45 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Castle Windsor]]></category>

		<category><![CDATA[Memory Management]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=718</guid>
		<description><![CDATA[We ran into a huge memory leak this week.  A bit of memory profiling with JetBrains&#8217; dotTrace quickly showed that the Windsor IoC container was holding on to a lot of references.  It turned out that i actually forgot to release the components i was requesting Windsor to construct for me.  I [...]]]></description>
			<content:encoded><![CDATA[<p>We ran into a huge memory leak this week.  A bit of memory profiling with JetBrains&#8217; <a href="http://www.jetbrains.com/profiler/index.html">dotTrace</a> quickly showed that the Windsor IoC container was holding on to a lot of references.  It turned out that i actually forgot to release the components i was requesting Windsor to construct for me.  I use the container in my web-layer to compose every page&#8217;s Controller with its dependencies. And in my service layer, i use the container to compose every RequestHandler and its dependencies.  So that&#8217;s two instances of the Container, in two separate AppDomains, and both are leaking a lot of memory due to my mistake.</p>
<p>My mistake was that after i was done with the components that i asked Windsor to resolve, i simply disposed them (which in turn would dispose their dependencies) and i figured that would be enough, since my components are registered as Transient.  That means that each time you request a Transient component, you get a new instance.  This led me to believe that Windsor wouldn&#8217;t need to hold a reference to the constructed components so i figured that simply disposing them would be enough, since they are IDisposables.  Disposing them is a good thing obviously, but because the container was still holding references to the requested components, that&#8217;s still a lot of memory that is being wasted because even though you&#8217;ve disposed them, they aren&#8217;t eligible for Garbage Collection until they are no longer accessible.  And because the container kept references to them, they remained accessible and were never collected.  And there was my memory leak.  Oops.</p>
<p>In order to prevent this problem in the future for myself and anyone else who reads this, let&#8217;s go over a few examples which should make it clear how you should make sure that your components are properly released so they are eligible for garbage collection.</p>
<p>Let&#8217;s start really simple.  We have an IController interface and a simple Controller class which implements the IController interface:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IController</span> : <span style="color: #2b91af;">IDisposable</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Controller</span> : <span style="color: #2b91af;">IController</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Disposed = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>In our tests, we&#8217;ll use the following method to create and configure the container:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: #2b91af;">WindsorContainer</span> CreateContainer()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> <span style="color: #2b91af;">WindsorContainer</span>();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(<span style="color: #2b91af;">Component</span>.For&lt;<span style="color: #2b91af;">IController</span>&gt;().ImplementedBy&lt;<span style="color: #2b91af;">Controller</span>&gt;().LifeStyle.Transient);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> container;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>The IController interface is registered with the container, and the container will return a new Controller instance (because of the Transient lifestyle) whenever someone requests an IController instance.</p>
<p>The following test highlights the memory leak that i was experiencing:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> ContainerKeepsReferenceToControllerIfWeOnlyDisposeOfIt()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> container = CreateContainer();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> controller = container.Resolve&lt;<span style="color: #2b91af;">IController</span>&gt;();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That(container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; controller.Dispose();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsTrue(controller.Disposed);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// the controller is disposed of, but the container is still keeping track</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// of the instance</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That(container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>When you request a component from the Container, it keeps a reference to that instance in its Kernel&#8217;s ReleasePolicy object.  If you merely dispose of your requested component, the ReleasePolicy still holds the reference to the component.  This is what caused my memory leak.</p>
<p>So how do we avoid this problem? It&#8217;s pretty easy actually:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> ContainerDoesNotKeepReferenceToControllerIfWeReleaseIt()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> container = CreateContainer();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> controller = container.Resolve&lt;<span style="color: #2b91af;">IController</span>&gt;();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That(container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// instead of disposing the controller, we&#8217;ll Release it through the container</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Release(controller);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsTrue(controller.Disposed);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// the controller is disposed of, and the container is no longer keeping</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// track of the instance</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>Instead of just disposing our controller, we tell the container to release it.  The container in turn knows that because IController inherits from IDisposable, it should dispose the Controller instance.  It also removes the instance from its Kernel&#8217;s ReleasePolicy object and once your own reference to the Controller instance goes out of scope, it&#8217;s eligible to be collected by the Garbage Collector.  </p>
<p>As you can see, it&#8217;s very easy to make sure your components are properly released and eligible for garbage collection.  But what about possible dependencies of your components?  Let&#8217;s take a look.</p>
<p>Suppose we define the following interface and implementation:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IDependency</span> { }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">MyDependency</span> : <span style="color: #2b91af;">IDependency</span> { }</p>
</div>
<p></code></p>
<p>The dependency doesn&#8217;t actually do anything, but bear with me <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>We modify the IController interface and Controller implementation like this:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IController</span> : <span style="color: #2b91af;">IDisposable</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">IDependency</span> Dependency { <span style="color: blue;">get</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Controller</span> : <span style="color: #2b91af;">IController</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">IDependency</span> Dependency { <span style="color: blue;">get</span>; <span style="color: blue;">private</span> <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> Controller(<span style="color: #2b91af;">IDependency</span> myDependency)</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dependency = myDependency;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Disposed = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>And then we modify the configuration of the container like this:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: #2b91af;">WindsorContainer</span> CreateContainer()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> <span style="color: #2b91af;">WindsorContainer</span>();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(<span style="color: #2b91af;">Component</span>.For&lt;<span style="color: #2b91af;">IController</span>&gt;().ImplementedBy&lt;<span style="color: #2b91af;">Controller</span>&gt;().LifeStyle.Transient);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Register(<span style="color: #2b91af;">Component</span>.For&lt;<span style="color: #2b91af;">IDependency</span>&gt;().ImplementedBy&lt;<span style="color: #2b91af;">MyDependency</span>&gt;().LifeStyle.Transient);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">return</span> container;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>Whenever we request an IController instance, the container will construct a Controller instance and will pass a MyDependency instance to the Controller&#8217;s instance constructor.  The question now is: does the container also track the instances of a requested component&#8217;s dependencies?  The answer is: no</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> ContainerDoesNotKeepReferenceToControllersDependencies()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> container = CreateContainer();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> controller = container.Resolve&lt;<span style="color: #2b91af;">IController</span>&gt;();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That(container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(container.Kernel.ReleasePolicy.HasTrack(controller.Dependency));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>We request an IController instance, which is tracked by the container.  The IController&#8217;s Dependency property contains an IDependency instance, which was also created by the container.  But as the last line of the test shows: the container does not track instances of the requested IController&#8217;s dependencies.</p>
<p>So what does that mean? If the dependencies don&#8217;t require any cleanup, then this is great.  We simply need to release the requested component, and the component and its dependencies will all be eligible for Garbage Collection.  But what happens when the dependencies need to be disposed?  Let&#8217;s take another look.</p>
<p>We modify the IDependency interface and MyDependency class so it looks like this:</p>
<p><code></p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">interface</span> <span style="color: #2b91af;">IDependency</span> : <span style="color: #2b91af;">IDisposable</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">MyDependency</span> : <span style="color: #2b91af;">IDependency</span></p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">bool</span> Disposed { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p>
<p style="margin: 0px;">&nbsp;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Disposed = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p>
</div>
<p></code></p>
<p>Now let&#8217;s see what happens with the Controller&#8217;s dependencies when we release the Controller:</p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span style="color: #2b91af;">Test</span>]</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> ContainerDoesNotDisposeControllersDisposableDependencies()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> container = CreateContainer();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> controller = container.Resolve&lt;<span style="color: #2b91af;">IController</span>&gt;();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">var</span> dependency = controller.Dependency;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.That(container.Kernel.ReleasePolicy.HasTrack(controller));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; container.Release(controller);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(container.Kernel.ReleasePolicy.HasTrack(controller));&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; </p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(container.Kernel.ReleasePolicy.HasTrack(dependency));</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsTrue(controller.Disposed);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">Assert</span>.IsFalse(dependency.Disposed);</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p>The container holds no references, but the Controller&#8217;s Dependency instance is not disposed!  Notice however that the Controller has been disposed by the container.  As i&#8217;ve mentioned <a href="http://davybrion.com/blog/2008/08/net-memory-management/">earlier</a>, if you own a reference to an IDisposable instance, you are responsible for properly disposing of that instance.  So we modify the Controller&#8217;s Dispose method so that it looks like this:</p>
<div style="font-family: Consolas; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Dispose()</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dependency.Dispose();</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Disposed = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<p>The previous test will now fail, because the Dependency will be properly disposed.</p>
<p>NOTE: i certainly don&#8217;t recommend to implement your Dispose methods like i just did.  This is just a simplified example.  The proper way to implement the Disposable Pattern is discussed <a href="http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/">here</a>.</p>
<p>Anyways, i hope it&#8217;s clear now how you can make sure your IoC usage does not cause memory leaks, and that everything is properly disposed of.</p>
<p class="addtoany_share_save_container">
    <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?sitename=The%20Inquisitive%20Coder%20-%20Davy%20Brion%27s%20Blog&amp;siteurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F&amp;linkname=The%20Importance%20Of%20Releasing%20Your%20Components%20Through%20Windsor&amp;linkurl=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F12%2Fthe-importance-of-releasing-your-components-through-windsor%2F" target="_blank"><img src="http://davybrion.com/blog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Save/Bookmark"/></a>

	</p>
<p><a href="http://feedads.googleadservices.com/~a/7m939FBfyM-SgI2Or0hsgVl6ztk/a"><img src="http://feedads.googleadservices.com/~a/7m939FBfyM-SgI2Or0hsgVl6ztk/i" border="0" ismap="true"></img></a></p><img src="http://feedproxy.google.com/~r/davybrion/~4/7k1KQzPJouM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://davybrion.com/blog/2008/12/the-importance-of-releasing-your-components-through-windsor/feed/</wfw:commentRss>
		<feedburner:origLink>http://davybrion.com/blog/2008/12/the-importance-of-releasing-your-components-through-windsor/</feedburner:origLink></item>
		<item>
		<title>Batching Remote Operations Is Not Premature Optimization</title>
		<link>http://feedproxy.google.com/~r/davybrion/~3/zeE48wZcaQE/</link>
		<comments>http://davybrion.com/blog/2008/12/batching-remote-operations-is-not-premature-optimization/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 22:14:09 +0000</pubDate>
		<dc:creator>Davy Brion</dc:creator>
		
		<category><![CDATA[Opinions]]></category>

		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://davybrion.com/blog/?p=702</guid>
		<description><![CDATA[I spent a day at Devoxx (formerly known as Javapolis) this week, and one of the presentations i saw was about common performance anti-patterns, given by Alois Reitbauer from DynaTrace.  While i didn&#8217;t really hear anything new during the presentation, i did kinda like how the speaker stressed that while premature optimization is indeed [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a day at <a href="http://www.devoxx.com/display/JV08/Home">Devoxx</a> (formerly known as Javapolis) this week, and one of the presentations i saw was about common performance anti-patterns, given by <a href="http://blog.dynatrace.com/author/alois-reitbauer/">Alois Reitbauer</a> from <a href="http://www.dynatrace.com/en/">DynaTrace</a>.  While i didn&#8217;t really hear anything new during the presentation, i did kinda like how the speaker stressed that while premature optimization is indeed evil, certain things simply don&#8217;t belong in that category and are things you should definitely keep an eye on throughout the development of your projects.</p>
<p>Those of you who&#8217;ve been reading this blog for a while know that i&#8217;ve often stressed the <a href="http://davybrion.com/blog/2008/06/the-query-batcher/">importance</a> <a href="http://davybrion.com/blog/2008/08/batching-sqlcommand-queries/">of</a> <a href="http://davybrion.com/blog/2008/06/batching-wcf-calls/">reducing</a> <a href="http://davybrion.com/blog/2008/07/batching/">the number</a> <a href="http://davybrion.com/blog/2008/09/the-select-command-batcher/">of</a> <a href="http://davybrion.com/blog/2008/10/batching-nhibernates-dm-statements/">remote</a> <a href="http://davybrion.com/blog/2008/11/why-on-earth-would-a-developer-do-this/">calls</a>.  Yeah that&#8217;s right, i just linked to 7 of my own posts in a single sentence :p</p>
<p>Anyways, there were a few people who thought that my preference for batching queries/service calls was actually a case of premature optimization, and that it was therefor evil and not something you should be doing until it was actually necessary to do so.  The speaker of the presentation explained that there is a difference between premature optimization and pro-active performance management.  Performance and scalability simply do not come for free, and you have to keep certain things in mind if you want your system to have those qualities.  </p>
<p>Now, before i go further, i would like to state that i do believe that clean, simple and reusable code is something that developers should always strive for.   I also believe that you should try to limit the number of times you hit the database, or the number of remote service calls you make in a single business transaction.  Those goals often seem to contradict each other.  There aren&#8217;t too many data access layers that allow you to easily perform multiple queries in a single roundtrip while still making sure that each query is reusable in a different context.  It gets even worse when it comes to remote services.  As you undoubtedly know, a lot of industry experts will r