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

<channel>
	<title>Ludwig's Blog</title>
	<atom:link href="http://ludwigstuyck.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ludwigstuyck.wordpress.com</link>
	<description>Adventures in .NET</description>
	<lastBuildDate>Thu, 05 Jan 2012 09:10:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ludwigstuyck.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ludwig's Blog</title>
		<link>http://ludwigstuyck.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ludwigstuyck.wordpress.com/osd.xml" title="Ludwig&#039;s Blog" />
	<atom:link rel='hub' href='http://ludwigstuyck.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Blog moved</title>
		<link>http://ludwigstuyck.wordpress.com/2010/05/29/blog-moved/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/05/29/blog-moved/#comments</comments>
		<pubDate>Sat, 29 May 2010 22:21:35 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=588</guid>
		<description><![CDATA[I moved my blog to http://www.dunatis.be.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=588&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I moved my blog to <a href="http://www.dunatis.be">http://www.dunatis.be</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/588/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=588&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/05/29/blog-moved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2010 style</title>
		<link>http://ludwigstuyck.wordpress.com/2010/05/03/visual-studio-2010-style/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/05/03/visual-studio-2010-style/#comments</comments>
		<pubDate>Mon, 03 May 2010 08:07:06 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=574</guid>
		<description><![CDATA[The default colors of visual studio are, well, kind of boring. But now it&#8217;s possbible to change that with only a few mouse clicks! First go to http://studiostyles.info and download your favorite style. Then, in visual studio 2010, select Tools &#62; Import and Export Settings: Check the Import selected environment settings, and click Next. You [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=574&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The default colors of visual studio are, well, kind of boring. But now it&#8217;s possbible to change that with only a few mouse clicks! First go to <a href="http://studiostyles.info">http://studiostyles.info</a> and download your favorite style. Then, in visual studio 2010, select <em>Tools &gt; Import and Export Settings</em>:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/importexport1.jpg"><img class="alignnone size-medium wp-image-576" title="importexport" src="http://ludwigstuyck.files.wordpress.com/2010/05/importexport1.jpg?w=298&#038;h=300" alt="" width="298" height="300" /></a></p>
<p>Check the <em>Import selected environment settings</em>, and click <em>Next</em>.</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/savesettings.jpg"><img class="alignnone size-medium wp-image-578" title="savesettings" src="http://ludwigstuyck.files.wordpress.com/2010/05/savesettings.jpg?w=298&#038;h=300" alt="" width="298" height="300" /></a></p>
<p>You probably want to save the current settings, so accept the default and click <em>Next</em>.</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/choose.jpg"><img class="alignnone size-medium wp-image-579" title="choose" src="http://ludwigstuyck.files.wordpress.com/2010/05/choose.jpg?w=298&#038;h=300" alt="" width="298" height="300" /></a></p>
<p>Then click the <em>Browse</em> button and select the template you downloaded:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/choosesetting.jpg"><img class="alignnone size-medium wp-image-580" title="choosesetting" src="http://ludwigstuyck.files.wordpress.com/2010/05/choosesetting.jpg?w=300&#038;h=223" alt="" width="300" height="223" /></a></p>
<p>&#8230;and then the <em>Next</em> button.</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/choosesetting2.jpg"><img class="alignnone size-medium wp-image-581" title="choosesetting2" src="http://ludwigstuyck.files.wordpress.com/2010/05/choosesetting2.jpg?w=298&#038;h=300" alt="" width="298" height="300" /></a></p>
<p>Finally click the <em>Finish</em> button.</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/progress.jpg"><img class="alignnone size-medium wp-image-582" title="progress" src="http://ludwigstuyck.files.wordpress.com/2010/05/progress.jpg?w=298&#038;h=300" alt="" width="298" height="300" /></a></p>
<p>And if everything was ok:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/importok.jpg"><img class="alignnone size-medium wp-image-584" title="importok" src="http://ludwigstuyck.files.wordpress.com/2010/05/importok.jpg?w=298&#038;h=300" alt="" width="298" height="300" /></a></p>
<p>Click <em>Close</em>, and behold the new style <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/05/newstyle.jpg"><img class="alignnone size-medium wp-image-585" title="newstyle" src="http://ludwigstuyck.files.wordpress.com/2010/05/newstyle.jpg?w=300&#038;h=253" alt="" width="300" height="253" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/574/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/574/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/574/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/574/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/574/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/574/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/574/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/574/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=574&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/05/03/visual-studio-2010-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/importexport1.jpg?w=298" medium="image">
			<media:title type="html">importexport</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/savesettings.jpg?w=298" medium="image">
			<media:title type="html">savesettings</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/choose.jpg?w=298" medium="image">
			<media:title type="html">choose</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/choosesetting.jpg?w=300" medium="image">
			<media:title type="html">choosesetting</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/choosesetting2.jpg?w=298" medium="image">
			<media:title type="html">choosesetting2</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/progress.jpg?w=298" medium="image">
			<media:title type="html">progress</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/importok.jpg?w=298" medium="image">
			<media:title type="html">importok</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/05/newstyle.jpg?w=300" medium="image">
			<media:title type="html">newstyle</media:title>
		</media:content>
	</item>
		<item>
		<title>Transform collection to comma separated list</title>
		<link>http://ludwigstuyck.wordpress.com/2010/04/27/transform-collection-to-comma-separated-list/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/04/27/transform-collection-to-comma-separated-list/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 08:47:02 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=569</guid>
		<description><![CDATA[Today I had to transform a collection of integers into a string in the form of a comma separated list. In the &#8216;old-style- approach it would probably be something like: List&#60;int&#62; numbers = new List&#60;int&#62;() { 1, 2, 3, 4, 5 }; StringBuilder strb = new StringBuilder(); foreach (int number in numbers) { strb.Append(number.ToString()); strb.Append(","); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=569&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I had to transform a collection of integers into a string in the form of a comma separated list. In the &#8216;old-style- approach it would probably be something like:</p>
<pre><span style="color:#800080;">List&lt;int&gt; numbers = new List&lt;int&gt;() { 1, 2, 3, 4, 5 };
StringBuilder strb = new StringBuilder();
foreach (int number in numbers)
{
    strb.Append(number.ToString());
    strb.Append(",");
}
string commeSeparatedList = strb.ToString().TrimEnd(',');</span></pre>
<p>But actually this can be done in a short way, like:</p>
<pre><span style="color:#800080;">List&lt;int&gt; numbers = new List&lt;int&gt;() { 1, 2, 3, 4, 5 };
string commeSeparatedList = string.Join(",", numbers.Select(n =&gt; n.ToString()).ToArray());</span></pre>
<p>which produces the same result. In my case it was not a collection of integers, but a list of objects; but is the same approach:</p>
<pre><span style="color:#800080;">string commaSeparatedListOfGroups = string.Join(",", allRelatedGroups.Select(g =&gt; g.Id.ToString()).ToArray());</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/569/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/569/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/569/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=569&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/04/27/transform-collection-to-comma-separated-list/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2010 installation</title>
		<link>http://ludwigstuyck.wordpress.com/2010/04/13/visual-studio-2010-installation/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/04/13/visual-studio-2010-installation/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 08:00:19 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=564</guid>
		<description><![CDATA[Visual Studio 2010 is out, and of course I installed it right away. During installation, it seemed that someone was getting really jealous<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=564&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Visual Studio 2010 is out, and of course I installed it right away. During installation, it seemed that someone was getting really jealous <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/04/jealous.jpg"><img class="alignnone size-medium wp-image-565" title="jealous" src="http://ludwigstuyck.files.wordpress.com/2010/04/jealous.jpg?w=300&#038;h=229" alt="" width="300" height="229" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/564/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=564&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/04/13/visual-studio-2010-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/04/jealous.jpg?w=300" medium="image">
			<media:title type="html">jealous</media:title>
		</media:content>
	</item>
		<item>
		<title>Sort projects alphabetically in Visual Studio</title>
		<link>http://ludwigstuyck.wordpress.com/2010/03/10/sort-projects-alphabetically-in-visual-studio/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/03/10/sort-projects-alphabetically-in-visual-studio/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 12:47:23 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=557</guid>
		<description><![CDATA[It is a well-known bug in Visual Studio that projects in solution folders are not sorted alphabetically. In solutions with a lot of projects this is often a problem, because it&#8217;s kind of hard to find the project you need. So I needed a way to permanently sort projects in solution folders, and it&#8217;s actually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=557&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It is a well-known bug in Visual Studio that projects in solution folders are not sorted alphabetically. In solutions with a lot of projects this is often a problem, because it&#8217;s kind of hard to find the project you need. So I needed a way to <strong>permanently </strong>sort projects in solution folders, and it&#8217;s actually very easy to do.</p>
<p>Let&#8217;s say you have the following visual studio solution:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/03/sort1.jpg"><img class="alignnone size-medium wp-image-558" src="http://ludwigstuyck.files.wordpress.com/2010/03/sort1.jpg?w=300&#038;h=233" alt="" width="300" height="233" /></a></p>
<p>The project <em>AAA </em>was added after the project <em>ZZZZZZ</em>, so it’s not alphabetically sorted. In order to sort it, right click the <em>ZZZZZZ </em>project and select <em>Rename</em>. Then select another project to end the edit. As you will see, the projects will be sorted:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/03/sort2.jpg"><img class="alignnone size-medium wp-image-559" src="http://ludwigstuyck.files.wordpress.com/2010/03/sort2.jpg?w=300&#038;h=221" alt="" width="300" height="221" /></a></p>
<p>And then, and this is important, <strong>be sure to</strong> <strong>collapse the solution folders</strong>, and then quit and restart Visual Studio. You will then see that the projects remain sorted!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/557/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/557/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/557/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=557&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/03/10/sort-projects-alphabetically-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/03/sort1.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/03/sort2.jpg?w=300" medium="image" />
	</item>
		<item>
		<title>Clone objects</title>
		<link>http://ludwigstuyck.wordpress.com/2010/03/03/clone-objects/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/03/03/clone-objects/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 15:17:47 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=526</guid>
		<description><![CDATA[Today a collegue asked for a clean way to clone objects in C#,  so that you really have different objects instead of a reference copy . So imagine that you have a class Employee as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } } [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=526&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today a collegue asked for a clean way to clone objects in C#,  so that you really have different objects instead of a reference copy . So imagine that you have a class Employee as follows:</p>
<pre><span style="color:#800080;">public class Employee
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
}</span></pre>
<div>and you would copy it:</div>
<pre><span style="color:#800080;">Employee original = new Employee()
{
  FirstName = "Homer",
  LastName = "Simpson",
};</span>
<span style="color:#800080;">Employee copy = original;
copy.FirstName = "Marge";
Console.WriteLine(string.Format("{0} {1}", original.FirstName, original.LastName));
Console.WriteLine(string.Format("{0} {1}", copy.FirstName, copy.LastName));</span></pre>
<div>Changing the first name of the copied object obviously also changes the first name of the original object, because it has been copied by refererence and so original and copy refer to the same object:</div>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/03/clone1.jpg"><img class="alignnone size-medium wp-image-527" src="http://ludwigstuyck.files.wordpress.com/2010/03/clone1.jpg?w=300&#038;h=49" alt="" width="300" height="49" /></a></p>
<div>And this was not wat we wanted.</div>
<div>To solve it, we first write an extension method that will be available on each class that implements the ICloneable interface:</div>
<pre><span style="color:#800080;">static class Extensions
{
  public static T Clone&lt;T&gt;(this T objectToClone) where T : ICloneable
  {
    return (T)objectToClone.Clone();
  }
}</span></pre>
<div>Next we have to make the Employee class implement the ICloneable interface:</div>
<pre><span style="color:#800080;">public class Employee : ICloneable
{
  public string FirstName { get; set; }
  public string LastName { get; set; }

  #region ICloneable Members
  public object Clone()
  {
   return new Employee() {FirstName = FirstName, LastName = LastName};
  }
 #endregion
}</span></pre>
<div>And if we now use the Clone method like:</div>
<pre><span style="color:#800080;">Employee copy = (Employee)original.Clone();</span></pre>
<div>then the new object is really a copy of the original:</div>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/03/clone2.jpg"><img class="alignnone size-medium wp-image-529" src="http://ludwigstuyck.files.wordpress.com/2010/03/clone2.jpg?w=300&#038;h=52" alt="" width="300" height="52" /></a></p>
<p>If you want to clone a list of objects, add an extension method like this:</p>
<pre><span style="color:#800080;">static class Extensions
{
  public static IList&lt;T&gt; Clone&lt;T&gt;(this IList&lt;T&gt; listToClone) where T : ICloneable
  {
    return listToClone.Select(item =&gt; (T)item.Clone()).ToList();
  }
}</span></pre>
<div>and to clone this list is then very simple:</div>
<pre><span style="color:#800080;">IList&lt;Employee&gt; copiedList = originalList.Clone();</span></pre>
<div>This example clones only the Employee object (known as shallow copy, see <a href="http://en.wikipedia.org/wiki/Object_copy" target="_blank">here</a>), but what if the Employee class contains other reference types? In this case we have to implement a deep copy, meaning that every subclass has to implement ICloneable too, for example, if you have a City:</div>
<pre><span style="color:#800080;">public class City: ICloneable
{
  public string CityName { get; set; }
  #region ICloneable Members
  public object Clone()
  {
    return new City() { CityName = CityName };
  }
  #endregion
}</span></pre>
<div>then Employee has to clone it like:</div>
<pre><span style="color:#800080;">public class Employee : ICloneable
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public City City{ get; set; }
  #region ICloneable Members
  public object Clone()
  {
    return new Employee() {FirstName = FirstName, LastName = LastName, <strong>City = (City)City.Clone()</strong> };
  }
  #endregion
}</span></pre>
<div>We can do one other improvement. As you see we always have to cast the Clone operation to its actual type. To solve  that we can create a generic ICloneable interface:</div>
<pre><span style="color:#800080;">interface ICloneable&lt;T&gt; : ICloneable
{
  new T Clone();
}</span></pre>
<div>and adapt the classes to it:</div>
<pre><span style="color:#800080;">public class Employee : ICloneable&lt;Employee&gt;
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public City City{ get; set; }
  #region ICloneable&lt;Employee&gt; Members
  Employee ICloneable&lt;Employee&gt;.Clone()
  {
    return new Employee() { FirstName = FirstName, LastName = LastName, City = City.Clone() };
  }
  #endregion

  #region ICloneable Members
  object ICloneable.Clone()
  {
    return new Employee() { FirstName = FirstName, LastName = LastName, City = City.Clone() };
  }
  #endregion
}

public class City : ICloneable&lt;City&gt;
{
  public string CityName { get; set; }
  #region ICloneable&lt;City&gt; Members
  public City Clone()
  {
    return new City() { CityName = CityName };
  }
  #endregion

  #region ICloneable Members
  object ICloneable.Clone()
  {
    return new City() { CityName = CityName };
  }
  #endregion
}</span></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/526/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/526/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/526/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=526&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/03/03/clone-objects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/03/clone1.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/03/clone2.jpg?w=300" medium="image" />
	</item>
		<item>
		<title>Castle MicroKernel/Windsor QuickStart 2: LifeStyle and LifeCycle</title>
		<link>http://ludwigstuyck.wordpress.com/2010/03/01/castle-microkernelwindsor-quickstart-2-servicelocator/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/03/01/castle-microkernelwindsor-quickstart-2-servicelocator/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 08:28:39 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Castle]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=500</guid>
		<description><![CDATA[&#8230;continued from part 1. Objectives In this Hands-On Lab, you will be introduced to the Castle MicroKernel/Windsor framework. In particular, you will: Understand LifeStyle Understand LifeCycle System requirements You must have the following items to complete this lab: Microsoft Visual Studio 2008 SP1 (professional edition) Prequisites You must have the following skills to understand this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=500&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230;continued from <a href="http://ludwigstuyck.wordpress.com/2010/02/26/castle-microkernelwindsor-quickstart-1-introduction/">part 1</a>.</p>
<h2>Objectives</h2>
<div id="_mcePaste">In this Hands-On Lab, you will be introduced to the Castle MicroKernel/Windsor framework. In particular, you will:</div>
<div id="_mcePaste">
<ul>
<li>Understand LifeStyle</li>
<li>Understand LifeCycle</li>
</ul>
</div>
<h2>System requirements</h2>
<div id="_mcePaste">You must have the following items to complete this lab:</div>
<div id="_mcePaste">
<ul>
<li>Microsoft Visual Studio 2008 SP1 (professional edition)</li>
</ul>
</div>
<h2>Prequisites</h2>
<div id="_mcePaste">You must have the following skills to understand this lab:</div>
<div id="_mcePaste">
<ul>
<li>Fundamental knowledge of software development in .NET 3.5</li>
<li>Basic knowledge of Castle</li>
</ul>
</div>
<h2>Understand LifeStyle</h2>
<div>
<p><strong>LifeStyle </strong>is a strategy that is related to an instance of a component. The supported lifestyles are:</p>
<ul>
<li><strong>Singleton</strong>: only one instance will be created for the whole life of the container. This is the default lifestyle.</li>
<li><strong>Transient</strong>: for each request a new instance if the component is created</li>
<li><strong>PerThread</strong>: for each thread there exists only one instance of a component</li>
<li><strong>Pooled</strong>: Instances will be pooled to avoid unnecessary constructions</li>
<li><strong>Custom</strong>: the instantiation of components is handled by your custom ILifestyleManager implementation</li>
</ul>
<div>
<p>The default lifestyle is singleton. To indicate which lifestyle you want to use, you can use attributes to decorate the class:</p>
</div>
<pre><span style="color:#800080;"><span style="color:#800080;"><strong>[Transient]</strong></span>
public class CustomerRepository : ICustomerRepository
{
    …
}</span></pre>
<div>
<p>or in the configuration file:</p>
</div>
<pre><span style="color:#800080;">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section
      name="castle"
      type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
      Castle.Windsor" /&gt;
  &lt;/configSections&gt;
  &lt;castle&gt;
    &lt;components&gt;
      &lt;component
        id="customer.business"
        service="CastleExample.ICustomerBusiness, CastleExample"
        <strong>lifestyle="transient"</strong>
        type="CastleExample.CustomerBusiness, CastleExample" /&gt;
      &lt;component
        id="customer.repository"
        service="CastleExample.ICustomerRepository, CastleExample"
        <strong>lifestyle="transient"</strong>
        type="CastleExample.MockCustomerRepository, CastleExample" /&gt;
    &lt;/components&gt;
  &lt;/castle&gt;
&lt;/configuration&gt;</span></pre>
<div>
<p>I prefer to do it in configuration because otherwise the code will be coupled again to the Castle container, or, in complicated projects, it may be handier to do it in code but in that case, create specific classes that are responsible for these configuration tasks, so that in your code you have as little as dependencies to Castle as possible.</p>
</div>
<div>
<p>So try this: add a transient lifestyle to the components in the configuration file, and to see the effect, modify the constructor of CustomerBusiness and add constructors to CustomerRepository and MockCustomerRepository as follows:</p>
</div>
<pre><span style="color:#800080;">public class CustomerBusiness : ICustomerBusiness
{
  private ICustomerRepository customerRepository;
  public CustomerBusiness(ICustomerRepository customerRepository)
  {
    // using constructor injection the concrete customer repository is injected
    this.customerRepository = customerRepository;
    <strong>Console.WriteLine("CustomerBusiness constructor");</strong>
  }
  …
}</span>

<span style="color:#800080;">public class CustomerRepository : ICustomerRepository
{
  <strong>public CustomerRepository()
  {
    Console.WriteLine("MockCustomerRepository constructor");
  }</strong>
  …
}

public class MockCustomerRepository : ICustomerRepository
{
  <strong>public MockCustomerRepository()
  {
    Console.WriteLine("MockCustomerRepository constructor");
  }</strong>
  …
}</span></pre>
<div>
<p>Modify Program.cs:</p>
</div>
<pre><span style="color:#800080;">static void Main(string[] args)
{
  …
  // Use business
  <strong>UseRegisteredBusiness();
  UseRegisteredBusiness();
  UseRegisteredBusiness();</strong>
}</span></pre>
<div>
<p>If you run the application, you will notice that each constructor is only called once and so there is only one instance created of the components for all calls:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/03/castle9.jpg"><img class="alignnone size-medium wp-image-515" src="http://ludwigstuyck.files.wordpress.com/2010/03/castle9.jpg?w=300&#038;h=59" alt="" width="300" height="59" /></a></p>
</div>
<div>
<p>Change the configuration that components use the transient lifestyle, and then run the application again to see the difference:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/03/castle10.jpg"><img class="alignnone size-medium wp-image-516" src="http://ludwigstuyck.files.wordpress.com/2010/03/castle10.jpg?w=300&#038;h=82" alt="" width="300" height="82" /></a></p>
</div>
<div>
<p>Now for each call of the business component, the constructors are called, which means that new objects are created for each call.</p>
</div>
<h2>Understand LifeCycle</h2>
<p>On the other hand there is <strong>LifeCycle</strong>, which<strong> </strong>is<strong> </strong>a strategy that is related to the different phases of an instance. It means that we can implement a number of interfaces; and these implementations are executed at the right time. Out of the box there are two groups of lifecycles:</p>
<ul>
<li><strong>Commission</strong>: these are executed when the component is being created. Interfaces are:
<ul>
<li>Castle.Model.IInitializable</li>
<li>System.ComponentModel.ISupportInitialize</li>
</ul>
</li>
<li><strong>Decommission</strong>: these are executed when the component is being destructed. Interface is:
<ul>
<li>System.IDisposable</li>
</ul>
</li>
</ul>
<p>So, bottom line: if you implement one of these interfaces for your component, Castle will take care of calling your implementations at the right time. Notice that if you use these, the coupling to Castle container will be higher.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/500/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/500/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/500/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/500/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/500/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/500/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/500/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/500/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=500&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/03/01/castle-microkernelwindsor-quickstart-2-servicelocator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/03/castle9.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/03/castle10.jpg?w=300" medium="image" />
	</item>
		<item>
		<title>Castle MicroKernel/Windsor QuickStart 1: introduction</title>
		<link>http://ludwigstuyck.wordpress.com/2010/02/26/castle-microkernelwindsor-quickstart-1-introduction/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/02/26/castle-microkernelwindsor-quickstart-1-introduction/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 16:38:18 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Castle]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=460</guid>
		<description><![CDATA[Objectives In this Hands-On Lab, you will be introduced to the Castle MicroKernel/Windsor framework. In particular, you will: Understand IoC and DI Download Castle Windsor Create a test application Use configuration file System requirements You must have the following items to complete this lab: Microsoft Visual Studio 2008 SP1 Prequisites You must have the following [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=460&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Objectives</h2>
<p>In this Hands-On Lab, you will be introduced to the <em>Castle MicroKernel/Windsor</em> framework. In particular, you will:</p>
<div id="_mcePaste">
<ul>
<li>Understand IoC and DI</li>
<li>Download Castle Windsor</li>
<li>Create a test application</li>
<li>Use configuration file</li>
</ul>
</div>
<h2>System requirements</h2>
<p>You must have the following items to complete this lab:</p>
<ul>
<li>Microsoft Visual Studio 2008 SP1</li>
</ul>
<h2>Prequisites</h2>
<p>You must have the following skills to understand this lab:</p>
<ul>
<li>Fundamental knowledge of software development in .NET 3.5</li>
</ul>
<h2><strong>Understand IoC and DI</strong></h2>
<p><span style="font-weight:normal;">Inversion of Control (<strong><em>IoC</em></strong>) and Dependency Injection (<strong><em>DI</em></strong>) are two related practices in software development which are known to lead to higher testability and maintainability of software products. </span></p>
<p><span style="font-weight:normal;">In the traditional way of coding, you instantiate the objects you want to use, so this means that at compile time you know which are the real classes you are going to interact with – you call them directly. So it means that you are in control, and not the consumers of your code. If you invert this, it would mean that you don’t know what the real classes are: someone else (the consumer) decides which will be the real classes, and how they will be instantiated. In this case you don’t know the concrete classes, but you only know the interfaces, and you don’t care about the actual implementation that is used. Therefore there are less dependencies and the coupling in a system is reduced. In fact, the control of dependency creation is pushed outside of the class itself. It is all about removing dependencies from your code.</span></p>
<p>A simple example: have a look at the following code:</p>
<pre><span style="color:#800080;">public class Car
{
  Engine engine;
  public Car()
  {
    engine = new Engine();
  }
}</span></pre>
<p>We have a extremely strongly dependency between Car and Engine, because the Engine is instantiated in the Car, so we can’t install any other engine inside this car. To make this code better, we change it slightly:</p>
<pre><span style="color:#800080;">public class Car
{
  IEngine engine;
  public Car(IEngine engine)
  {
    this.engine = engine;
  }
}</span></pre>
<p>Notice the difference? The control of creation of the engine has been moved out of the car.  Now the code that creates the car also chooses the engine:  this is inversion of control. Inversion of control is also known as the Hollywood principle: ‘don’t call me, I call you’, so in this case it’s like the Engine class saying to the Car class: ‘don’t create me, I will be created by someone else’.</p>
<p><span style="font-weight:normal;">Another concrete (simplified) example: in the following picture, a client uses the <em>CustomerBusiness</em> component, which uses the <em>CustomerRepository</em> component to access the database. You see that <em>CustomerBusiness</em> has a hard reference to the concrete <em>CustomerRepository</em>:</span></p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle1.jpg"><img class="alignnone size-full wp-image-462" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle1.jpg" alt="" width="265" height="246" /></a></p>
<p>Now imagine that we want to add unit tests to test the business component:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle2.jpg"><img class="alignnone size-medium wp-image-463" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle2.jpg?w=300&#038;h=142" alt="" width="300" height="142" /></a></p>
<p>Now we have a problem, because when we test the business component we don’t want it to use the real <em>CustomerRepository</em> but a mock implementation of it. In the current architecture, we do not have this flexibility. To solve this, we can use the <strong><em>IoC</em></strong> pattern: let the <em>Client</em> and <em>Unit test</em> decide which repository the business component should use.  So, the <em>CustomerBusiness</em> component no longer decides what repository it uses. To achieve this, we create a <em>ICustomerRepository</em> interface. This interface is then implemented by the <em>CustomerRepository</em> (this implementation uses the real database) and also by the <em>MockCustomerRepository</em> (this implementation uses no database, but mock data). The <em>CustomerBusiness</em> component now has only a reference to the <em>ICustomerRepository</em> interface, and it doesn’t know what the real implementation is, and it doesn’t care:</p>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle3.jpg"><img class="alignnone size-medium wp-image-464" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle3.jpg?w=300&#038;h=182" alt="" width="300" height="182" /></a></p>
<p>The control of which repository is used is inverted to the client (wants the business component to use <em>CustomerRepository</em>) and the unit test (wants the business component to use <em>MockCustomerRepository</em>).</p>
<p>In a further step we can do the same for every component: create your interface first and then one or more implementations. So in our example also the business component can be abstracted, although we have only one implementation at this time:</p>
<div><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle4.jpg"><img class="alignnone size-medium wp-image-465" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle4.jpg?w=300&#038;h=213" alt="" width="300" height="213" /></a></div>
<div>It takes a while to understand this approach because it’s a mind shift and has a certain learning curve: the way you build your software changes. But using these principles eventually lead to better structured, modularized, testable and maintainable applications. Once you get used to it, it actually becomes a habit to build software this way.</div>
<div>
<div>To summarize, the advantages are:</div>
<div>
<ul>
<li>loose coupling between components: you share contracts, not implementations</li>
<li>flexibility: it’s easy to change behavior</li>
<li>easy to test components: replace dependencies by mocking components so that you can really test what you want to test</li>
<li>improve code reuse: each component has its responsibility</li>
<li>extensibility: future changes can be implemented easily by injecting new implementations</li>
</ul>
</div>
</div>
<div>
<div>Dependency creation is often delegated to inversion of control containers, frameworks that allow needed dependencies to be injected automatically; this process is called dependency injection.</div>
<div>There are a number of such frameworks that supply these patterns, like Castle, StructureMap, Spring.NET, Autofac, Unity, NInject and others, but they all implement about the same principles; although Castle has also a number of aspect oriented features. In these quickstarts we will be using Castle.</div>
</div>
<h2>Download Castle</h2>
<p>You need the Castle Project assemblies on your local machine, so download the project release at<a href="http://www.castleproject.org/castle/download.html" target="_blank"> http://www.castleproject.org/castle/download.html</a>.</p>
<h2>Create a test application</h2>
<p>We are going to create a simple test application to demonstrate the basics of Castle. Start Visual Studio and create a new console application called CastleExample. Add references to the following assemblies:</p>
<ul>
<li>Castle.Core.dll</li>
<li>Castle.DynamicProxy2.dll</li>
<li>Castle.MicroKernel.dll</li>
<li>Castle.Windsor.dll</li>
</ul>
<p>We are going to implement the example from previous chapter in a simple way, focusing on how to use Castle to achieve dependency injection. We start by defining the domain object for customer, so add a new class Customer:</p>
<pre>
<div><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;</span><span style="color:#800080;">
</span></div>
<div><span style="color:#800080;">namespace CastleExample
</span><span style="color:#800080;">{
 </span><span style="color:#800080;">   public class Customer
</span><span style="color:#800080;">    {
</span><span style="color:#800080;">        public int Id{ get; set; }
</span><span style="color:#800080;">        public string FirstName { get; set; }
</span><span style="color:#800080;">        public string LastName { get; set; }
</span><span style="color:#800080;">    }
</span><span style="color:#800080;">}</span></div>
</pre>
<div>Then we design the interface for the customer repository. Add a new class <em>ICustomerRepository</em>:</div>
<pre><span style="color:#800080;">using System;
</span><span style="color:#800080;">using System.Collections.Generic;
</span><span style="color:#800080;">using System.Linq;
</span><span style="color:#800080;">using System.Text;
</span><span style="color:#800080;">namespace CastleExample
</span><span style="color:#800080;">{
</span><span style="color:#800080;">    public interface ICustomerRepository
</span><span style="color:#800080;">    {
</span><span style="color:#800080;">        Customer CreateCustomer(Customer customer);
</span><span style="color:#800080;">        List&lt;Customer&gt; ReadCustomers();
</span><span style="color:#800080;">        void DeleteCustomer(int Id);
</span><span style="color:#800080;">    }
</span><span style="color:#800080;">}</span></pre>
<div>We already now that we will have two implementations for this interface: a real one, using a database; and one that uses mock data. For the real one, add a class <em>CustomerRepository</em>:</div>
<pre><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CastleExample
{
    public class CustomerRepository : ICustomerRepository
    {
        #region ICustomerRepository Members
        public Customer CreateCustomer(Customer customer)
        {
            // TO DO: Create customer in database here
            Console.WriteLine("CreateCustomer in CustomerRepository");
            return null;
        }
        public List&lt;Customer&gt; ReadCustomers()
        {
            // TO DO: Read customers from database here
            Console.WriteLine("ReadCustomers in CustomerRepository");
            return null;
        }
        public void DeleteCustomer(int Id)
        {
            // TO DO: Delete customer in database here
            Console.WriteLine("DeleteCustomer in CustomerRepository");
        }
        #endregion
    }
}</span></pre>
<p>For the mock repository, add a class <em>MockCustomerRepository</em>:</p>
<pre>
<div><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;</span></div>
<div><span style="color:#800080;">namespace CastleExample
{
    public class MockCustomerRepository : ICustomerRepository
    {
        #region ICustomerRepository Members</span></div>
<div><span style="color:#800080;">        public Customer CreateCustomer(Customer customer)
        {
            // Mock a newly created customer
            Console.WriteLine("CreateCustomer in MockCustomerRepository");
            return null;
        }</span></div>
<div><span style="color:#800080;">        public List&lt;Customer&gt; ReadCustomers()
        {
            // Mock a list of customers
            Console.WriteLine("ReadCustomers in MockCustomerRepository");
            return null;
        }</span></div>
<div><span style="color:#800080;">        public void DeleteCustomer(int Id)
        {
            // Mock delete
            Console.WriteLine("DeleteCustomer in MockCustomerRepository");
        }</span></div>
<div><span style="color:#800080;">        #endregion
    }
}</span></div>
</pre>
<p>Note that we don’t actually implement <em>CustomerRepository</em> and <em>MockCustomerRepository</em>, we just use <em>Console.WriteLine</em> to demonstrate the effect later.</p>
<div>Now let’s write the <em>Main</em> method in the <em>Program.cs</em> file:</div>
<pre>
<div><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Windsor;
namespace CastleExample
{
    class Program
    {
        private static IWindsorContainer container;
        static void Main(string[] args)
        {
            // Register components
            container = new WindsorContainer();
            container.AddComponent&lt;ICustomerRepository,
                     CustomerRepository&gt;("customer.repository");
            // Use repository
            UseRegisteredRepository();
        }</span></div>
<div><span style="color:#800080;">        public static void UseRegisteredRepository()
        {
            // Get the actual registered customer repository
            ICustomerRepository customerRepository =
                    container.Resolve&lt;ICustomerRepository&gt;();
            customerRepository.ReadCustomers();
        }
    }
}</span></div>
</pre>
<div>In the <em>Main</em> method we first initialize a new <em>WindsorContainer</em> object, and then we indicate that whenever a <em>ICustomerRepository</em> interface is used in our code, we want the actual object to be of type <em>CustomerRepository</em>. So here we register the component, which doesn’t mean that it is already instantiated – this is only done when it’s needed.</div>
<div>Then, in the <em>UseRegisteredRepository</em> method, we use the container again to get the actual customer repository and we can use its methods.</div>
<div>Run the application, and as expected we can see that the <em>ReadCustomers</em> of the <em>CustomerRepository</em> class is being called:</div>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle5.jpg"><img class="alignnone size-medium wp-image-467" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle5.jpg?w=300&#038;h=83" alt="" width="300" height="83" /></a></p>
<div>
<p>Now let’s change this so that the <em>MoclCustomerRepository</em> is used:</p>
<pre><span style="color:#800080;">static void Main(string[] args)
{
    // Register components
    container = new WindsorContainer();
    container.AddComponent&lt;ICustomerRepository,
                   MockCustomerRepository&gt;("customer.repository");

   // Use repository     UseRegisteredRepository();
}</span></pre>
<div>Run the application again, and verify that this time the <em>ReadCustomers</em> of the <em>MockCustomerRepository</em> class is being called:</div>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle6.jpg"><img class="alignnone size-medium wp-image-476" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle6.jpg?w=300&#038;h=81" alt="" width="300" height="81" /></a></p>
<p>Let’s add the business component. Again, first add a class <em>ICustomerBusiness</em> for the interface:</p>
<pre><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CastleExample
{
    public interface ICustomerBusiness
    {
        Customer AddCustomer(Customer customer);
        List&lt;Customer&gt; GetCustomers();
        void RemoveCustomer(int Id);
    }
}</span></pre>
<div>We know we have one implementation at the moment, so add a class <em>CustomerBusiness</em> as follows:</div>
<pre><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CastleExample
{
    public class CustomerBusiness : ICustomerBusiness
    {
        private ICustomerRepository customerRepository;
        public CustomerBusiness(ICustomerRepository customerRepository)
        {
            // using constructor injection the concrete customer repository is injected
            this.customerRepository = customerRepository;
        }
        #region ICustomerBusiness Members
        public Customer AddCustomer(Customer customer)
        {
            return customerRepository.CreateCustomer(customer);
        }
        public List&lt;Customer&gt; GetCustomers()
        {
            return customerRepository.ReadCustomers();
        }
        public void RemoveCustomer(int Id)
        {
            customerRepository.DeleteCustomer(Id);
        }
        #endregion
    }
}</span></pre>
<div>
<p>Note that we never instantiate the customer repository that is to be used. Instead, in the constructor we accept a parameter of type <em>ICustomerRepository</em>, and we use that in the business component without caring about what the real implementation looks like. Thanks to <strong><span style="text-decoration:underline;">constructor injection</span></strong>, the real object to be used will be injected by the caller.</p>
<p>Finally, modify <em>Program.cs</em> to test this:</p>
</div>
<pre><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Windsor;
namespace CastleExample
{
    class Program
    {
        private static IWindsorContainer container;
        static void Main(string[] args)
        {
            // Register components
            container = new WindsorContainer();
            <strong>container.AddComponent&lt;ICustomerBusiness,
                            CustomerBusiness&gt;("customer.business");</strong>
            container.AddComponent&lt;ICustomerRepository,
                       MockCustomerRepository&gt;("customer.repository");
            // Use repository
            UseRegisteredRepository();
            <strong>// Use business
            UseRegisteredBusiness();</strong>
        }
        public static void UseRegisteredRepository()
        {
            // Get the actual registered customer repository
            ICustomerRepository customerRepository =
                container.Resolve&lt;ICustomerRepository&gt;();
            customerRepository.ReadCustomers();
        }
       <strong> public static void UseRegisteredBusiness()
        {
            // Get the actual registered customer business
            ICustomerBusiness customerBusiness =
               container.Resolve&lt;ICustomerBusiness&gt;();
            customerBusiness.GetCustomers();
        }</strong>
    }
}</span></pre>
<div>
<p>Now the <em>Main</em> method decides what business component will be used (<em>CustomerBusiness</em>), and what repository component will be used (<em>MockCustomerRepository</em>). When the <em>CustomerBusiness</em> object is created, Castle notices that it has a constructor that accepts an interface (<em>ICustomerRepository</em>) and injects the actual implementation for this interface as configured in the beginning of the <em>Main</em> method.</p>
<p>Run the application again to see if the second line in the console output is indeed <em>MockCustomerRepository</em>:</p>
</div>
<p><a href="http://ludwigstuyck.files.wordpress.com/2010/02/castle7.jpg"><img class="alignnone size-medium wp-image-477" src="http://ludwigstuyck.files.wordpress.com/2010/02/castle7.jpg?w=300&#038;h=81" alt="" width="300" height="81" /></a></p>
<p>To summarize, what we have done it enabled the client to choose which actual implementations of <em>ICustomerBusiness</em> and <em>ICustomerRepository</em> it wants to use. The business component itself only knows the interface of the repository, not the actual implementation. It means that we now have a way to easily change the implementation: a real client would register the real <em>CustomerRepository</em>, a unit test would register the <em>MockCustomerRepository</em>.</p>
<p>To demonstrate another form of injection, <strong><span style="text-decoration:underline;">property injection</span></strong>, create a new class Tester that contains our testing methods and also two properties customerBusiness and customerRepository :</p>
<pre><span style="color:#800080;">public class Tester
{
  // These properties will be injected
  public ICustomerBusiness customerBusiness { get; set;}
  public ICustomerRepository customerRepository { get; set; }
  public void UseRegisteredRepository()
  {
    // Get the actual registered customer repository
    customerRepository.ReadCustomers();
  }

  public void UseRegisteredBusiness()
  {
    // Get the actual registered customer business
    customerBusiness.GetCustomers();
  }
}</span></pre>
<p>and change the Main() method as follows:</p>
<pre><span style="color:#800080;">static void Main(string[] args)
{
  // Register components
  container = new WindsorContainer();
  container.AddComponent&lt;ICustomerBusiness,
         CustomerBusiness&gt;("customer.business");
  container.AddComponent&lt;ICustomerRepository,
         MockCustomerRepository&gt;("customer.repository");
  container.AddComponent&lt;Tester, Tester&gt;("tester"); </span>
<span style="color:#800080;">  Tester tester = container.Resolve&lt;Tester&gt;();
  tester.UseRegisteredRepository();
  tester.UseRegisteredBusiness();
}</span></pre>
<p>As you can see the Tester class has to properties that will be injected automatically by Castle when they are used.</p>
<p>Note however that the use of constructor injection is preferred, because when  you use this you have an explicit indication of a dependency that has to be fulfilled – you know it at compile time. If you use property injection, run-time exceptions may occur.</p>
<h2>Use configuration file</h2>
<p>In the previous example we used code to configure the container, but of course we have more flexibility if we would be able to do that in a configuration file.<br />
Add a configuration file to the project, and add a section to configure Windsor Container:</p>
<pre><span style="color:#800080;">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section
        name="castle"
        type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
              Castle.Windsor" /&gt;
  &lt;/configSections&gt;
  &lt;castle&gt;
    &lt;components&gt;
    &lt;/components&gt;
  &lt;/castle&gt;
&lt;/configuration&gt;</span></pre>
<p>Then add the components we need:</p>
<pre><span style="color:#800080;">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section
        name="castle"
        type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
              Castle.Windsor" /&gt;
  &lt;/configSections&gt;
  &lt;castle&gt;
    &lt;components&gt;
     <strong> &lt;component
           id="customer.business"
           service="CastleExample.ICustomerBusiness, CastleExample"
           type="CastleExample.CustomerBusiness, CastleExample" /&gt;
      &lt;component
          id="customer.repository"
          service="CastleExample.ICustomerRepository, CastleExample"
          type="CastleExample.MockCustomerRepository, CastleExample" /&gt;</strong>
    &lt;/components&gt;
  &lt;/castle&gt;
&lt;/configuration&gt;</span></pre>
<p>Finally, we need to create the Windsor Container passing a configuration interpreter and a resource in the <em>Main</em> method:</p>
<pre><span style="color:#800080;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Core.Resource;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
namespace CastleExample
{
    class Program
    {
        private static IWindsorContainer container;
        static void Main(string[] args)
        {
            // Register components
            <strong>container =
                new WindsorContainer(
                    new XmlInterpreter(new ConfigResource("castle")));</strong>

            // Use repository
            UseRegisteredRepository();
            // Use business
            UseRegisteredBusiness();
        }
        public static void UseRegisteredRepository()
        {
            // Get the actual registered customer repository
            ICustomerRepository customerRepository =
                container.Resolve&lt;ICustomerRepository&gt;();
            customerRepository.ReadCustomers();
        }
        public static void UseRegisteredBusiness()
        {
            // Get the actual registered customer business
            ICustomerBusiness customerBusiness =
                container.Resolve&lt;ICustomerBusiness&gt;();
            customerBusiness.GetCustomers();
        }
    }
}</span></pre>
<p>Run the application and it will now use the configuration file.</p>
<p>In the <a href="http://ludwigstuyck.wordpress.com/2010/03/01/castle-microkernelwindsor-quickstart-2-servicelocator/">next part</a> we will investigate LifeStyle and LifeCycle.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/460/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=460&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/02/26/castle-microkernelwindsor-quickstart-1-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle1.jpg" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle2.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle3.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle4.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle5.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle6.jpg?w=300" medium="image" />

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/02/castle7.jpg?w=300" medium="image" />
	</item>
		<item>
		<title>A reference architecture (Part 2)</title>
		<link>http://ludwigstuyck.wordpress.com/2010/01/20/a-reference-architecture-part-2-2/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/01/20/a-reference-architecture-part-2-2/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 09:25:45 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=435</guid>
		<description><![CDATA[&#8230;continued from part 1. In the previous part of this series I explained the general architectural guidelines. Of  course it is very important to have a consistent organization of all the solutions and projects in an organization, so that&#8217;s what I will discuss in this post. Solution structure The general pre-defined structure of solution and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=435&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230;continued from <a href="http://ludwigstuyck.wordpress.com/2010/01/12/a-reference-architecture-part-1/">part 1</a>.</p>
<p>In the previous part of this series I explained the general architectural guidelines. Of  course it is very important to have a consistent organization of all the solutions and projects in an organization, so that&#8217;s what I will discuss in this post.</p>
<h1>Solution structure</h1>
<div id="_mcePaste">The general pre-defined structure of solution and projects looks like this:</div>
<div>
<div id="attachment_444" class="wp-caption alignnone" style="width: 237px"><a href="http://ludwigstuyck.files.wordpress.com/2010/01/solution12.jpg"><img class="size-medium wp-image-444" title="Solution structure" src="http://ludwigstuyck.files.wordpress.com/2010/01/solution12.jpg?w=227&#038;h=300" alt="Solution structure" width="227" height="300" /></a><p class="wp-caption-text">Solution structure</p></div>
</div>
<div>As you can see this structure reflects the architectural layers as described in previous part of this series:</div>
<div>
<ul>
<li>The <strong>Manager </strong>solution folder contains all managers</li>
<li>The <strong>Agent </strong>solution folder contains all agents</li>
<li>The <strong>Utility </strong>solution folder contains all utilities</li>
<li>The <strong>BusinessEntity </strong>solution folder contains all business entities</li>
<li>The <strong>Client </strong>solution folder contains all client applications</li>
</ul>
</div>
<h2>Manager solution folder in detail</h2>
<p>Each manager has the same structure. As an example, this is how the structure of the Stock manager looks like:</p>
<div id="attachment_437" class="wp-caption alignnone" style="width: 165px"><a href="http://ludwigstuyck.files.wordpress.com/2010/01/solution2.jpg"><img class="size-medium wp-image-437" title="Manager structure" src="http://ludwigstuyck.files.wordpress.com/2010/01/solution2.jpg?w=155&#038;h=300" alt="Manager structure" width="155" height="300" /></a><p class="wp-caption-text">Manager structure</p></div>
<p>Again, this reflects the architectural design as described earlier: the Stock manager is located in the solution folder <em>Manager\Stock</em>. This folder has the following projects:</p>
<ul>
<li><strong>Schepers.Manager.Stock.ServiceInterface</strong>: service contracts, message contracts and data contracts of the Stock manager</li>
<li><strong>Schepers.Manager.Stock.ServiceAdapter</strong>: service adapter of the Stock manager</li>
<li><strong>Schepers.Manager.Stock.Business</strong>: business logic of the Stock manager</li>
</ul>
<h2 style="font-size:1.5em;">Agent and utility solution folder in detail</h2>
<p>The agent and utility structure is identical to the manager structure, except that we also have ResourceAccess projects. As an example, have a look at the structure of the Email utility:</p>
<div id="attachment_445" class="wp-caption alignnone" style="width: 212px"><a href="http://ludwigstuyck.files.wordpress.com/2010/01/solution3.jpg"><img class="size-medium wp-image-445" title="Agent/Utility structure" src="http://ludwigstuyck.files.wordpress.com/2010/01/solution3.jpg?w=202&#038;h=300" alt="Agent/Utility structure" width="202" height="300" /></a><p class="wp-caption-text">Agent/Utility structure</p></div>
<p>the Email utility is located in the solution folder <em>Utility\Email</em>, and has the following projects:</p>
<ul>
<li><strong>Schepers.Utility.Email.ServiceInterface</strong>: contains service contracts, message contracts and data contracts of the Email utility</li>
<li><strong>Schepers.Utility.Email.ServiceAdapter</strong>: service adapter of the Email utility</li>
<li><strong>Schepers.Utility.Email.Business</strong>: business logic of the Email utility</li>
<li><strong>Schepers.Utility.Email.ResourceAccess.Repository</strong>: repository of the Email utility</li>
<li><strong>Schepers.Utility.Email.ResourceManager.NetMail</strong>: resource manager of the Email utility</li>
</ul>
<h2>BusinessEntity folder in detail</h2>
<p>The project containing all business entities looks like:</p>
<div id="attachment_449" class="wp-caption alignnone" style="width: 232px"><a href="http://ludwigstuyck.files.wordpress.com/2010/01/solution4.jpg"><img class="size-full wp-image-449" title="Business entities" src="http://ludwigstuyck.files.wordpress.com/2010/01/solution4.jpg" alt="Business entities" width="222" height="148" /></a><p class="wp-caption-text">Business entities</p></div>
<p>In more complicated environments you can use solution folders to divide the various business entities in categories.</p>
<h2>Client folder in detail</h2>
<p>The client folder contains all client projects:</p>
<div id="attachment_450" class="wp-caption alignnone" style="width: 310px"><a href="http://ludwigstuyck.files.wordpress.com/2010/01/solution5.jpg"><img class="size-medium wp-image-450" title="Client projects" src="http://ludwigstuyck.files.wordpress.com/2010/01/solution5.jpg?w=300&#038;h=164" alt="Client projects" width="300" height="164" /></a><p class="wp-caption-text">Client projects</p></div>
<h2>Other folders</h2>
<p>If needed, you can add other solution folders, for example a <em>Test </em>folder that contains all unit tests for your projects.</p>
<h2><strong>Solution separation</strong></h2>
<p>Solutions are all put in a separate folder, and we define two types of Visual Studio solutions: entity and master solutions.</p>
<h3>Entity solutions</h3>
<p>The idea of an entity solution is that it should contain only those projects relevant for the solution, and relevant to one deployable entity (that may consist of a number of assemblies). So entity solutions never mix separate deployable projects, for example:</p>
<p>Solutions<br />
\Schepers.Utility.Email.ResourceAccess-VS2008.sln (contains only resource access projects)<br />
\Schepers.Manager.Stock.Business-VS-2008.sln (contains only business project)</p>
<p>Obviously, this approach has a number of advantages:</p>
<ul>
<li>You see only what is relevant for the project</li>
<li>You only build the smallest relevant deployable entity</li>
<li>Various team can work on separate solutions without having to worry about conflicts</li>
</ul>
<h3>Master solutions</h3>
<p>A master solution contains all projects that are involved in a business application, so it moves beyond the boundaries of the entity solution because it contains parts that are going to be deployed separately. A master solution is typically used for testing purposes, that is to say: to test the entire business solution. Example:</p>
<p>Solutions<br />
\Schepers.Master-VS2008.sln (contains all projects for this customer)<br />
\Schepers.Manager.Stock-VS-2008.sln (contains all projects related to the Stock manager)</p>
<h1>Guidelines</h1>
<h2>Folder and file names</h2>
<p>Inside visual studio, folder names are short: Utility, Agent, Client,&#8230; but project names contain the full namespace: Schepers.Manager.Stock.ServiceInterface, Schepers.Utility.Email.ResourceAccess.ResourceManager.netMail,&#8230;</p>
<h2>Naming conventions</h2>
<p>This one is easy: we use the naming conventions as defined at <a href="http://msdn.microsoft.com/en-us/library/xzf533w0(VS.71).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/xzf533w0(VS.71).aspx</a>.</p>
<h2>Contract namespaces</h2>
<p>It’s important to have naming conventions for the contract namespaces and that we apply them in a consistent way.</p>
<h3>Starting points</h3>
<p>These are some starting points concerning naming guidelines:</p>
<ul>
<li>a contract namespace should make clear to what domain data and message contracts belong to. It does not care about the solution structure (the .NET namespace) that is being used.</li>
<li>a contract namespace includes a version indication</li>
<li>a contract namespace is in lower case</li>
<li>a contract namespace does not care about it&#8217;s an enumeration or other specific type</li>
<li>a contract namespace does not contain the name of the property itself</li>
</ul>
<h3>Conventions</h3>
<p>Convention for data contracts: http://schemas.schepers.com/servicetype.servicename/subspecification/yyyy/mm/dd</p>
<p>Convention for message contracts: http://schemas.schepers.com/servicetype.servicename/request-response-name/yyyy/mm/dd</p>
<p>where</p>
<ul>
<li>servicetype is the type of service (agent, manager, utility, cross,…) without &#8216;service&#8217; (mandatory)</li>
<li>servicename is the name of the service (storage, user,…) (mandatory)</li>
<li>subspecification is a sub-category when needed (render, view, abstract,…) (optional)</li>
<li>yyyy is the year in four digits (2009, 2010,…) (mandatory)</li>
<li>mm is the month in two digits (04, 11,…) (mandatory)</li>
<li>dd is the day in two digits (06, 24,…) (mandatory)</li>
<li>request-response-name is the name of the request or response it belongs too (addbookmarkrequest, addbookmarkresponse,…) (mandatory)</li>
</ul>
<p>For versioning we choose a date indication yyyy/mm/dd instead of version number, because it’s a W3C standard and has more meaning.</p>
<h3>Example</h3>
<p>The contract namespaces for the EmailService are named as follows:</p>
<ul>
<li>data contracts
<ul>
<li>EmailAddress: http://schemas.schepers.com/utility.email/2009/07/02</li>
<li>EmailAttachment: http://schemas.schepers.com/utility.email/2009/07/02</li>
<li>EmailPriority: http://schemas.schepers.com/utility.email/2009/07/02</li>
</ul>
</li>
<li>message contracts
<ul>
<li>SendEmailRequest: http://schemas.schepers.com/utility.email/sendemailrequest/2009/07/02</li>
</ul>
</li>
</ul>
<h1>Advantages and disadvantages</h1>
<p>Although the amount of layers may seem overwhelming at first, evolving to a service oriented design has undoubtedly advantages for IT as well as business.</p>
<h2>Advantages for IT</h2>
<h3>Loose coupling</h3>
<p>Services are loosely coupled, meaning that they work entirely independent from each other; so changing one service does not affect another service in anyway. Because of the layered approach, this is also true for each other component in the architecture. Examples:</p>
<ul>
<li>If a resource manager changes or is replaced, it has no impact on the existing assets and consumers won’t even notice.</li>
<li>A real implementation can easily be replaced by a mock implementation</li>
</ul>
<h3>Single-Responsibility</h3>
<p>The Single-Responsibility principle means that a class should have only one responsibility, and has therefore only one reason to change. Examples:</p>
<ul>
<li>The resource manager’s task is to implement resource access to a specific resource and using a specific technology (for example, using LINQ). It’s about data logic, no business or other logic.</li>
<li>A repository is an abstraction of the data functionality needed for a service. It contains only the abstraction for that particular service, and only uses the resource manager(s) needed for its scope.</li>
<li>An agent is fine-grained; it offers functionality within its limited scope only.</li>
</ul>
<h3>Interface Segregation Principle</h3>
<p>According to the Interface Segregation Principle, many client specific interfaces are better than one general purpose interface, so we design our services in such a way that they expose tailored business functionality to clients and only what they really need. Because of this, services are more robust and better maintainable, due to fewer dependencies. Of course, a service should describe its capabilities and characteristics in a clear and stateless (no shared context) way without hidden assumptions. If this is done well, redundancy is low and by combining and recombining services project delivery will speed up – with lowered costs as a logical consequence. It promotes reuse on business and technological level: use what’s already there and extend what you already have. It also results in a very scalable solution: it is easy to scale out your services by deploying them into a load-balanced server farm, using software load balancers as well as hardware solutions.</p>
<h3>Same mindset</h3>
<p>If everyone has the same mindset, it’s easier to work together. Same approach, same methodology, same vision makes it possible to better understand what everyone is doing and how things work. There is a one-time investment of learning this – but because the entire team uses it, the inter-group collaboration becomes a lot better because we are already speaking the same architectural language.</p>
<h2>Advantages for business</h2>
<h3>Think business, not technology</h3>
<p>The design forces you to think in terms of business processes and service interactions, instead of monolithic applications. Therefore business has a clear view on what capabilities are available without having to worry about implementation details or technology choices. Example: business should not care how data is stored! Business changes can be implemented faster, because business handling is done in 1 place only by the development team in collaboration with business team. Moreover, business and IT speak the same business language – not technology!</p>
<h3>Eliminate redundancy</h3>
<p>Services can be leveraged cross multiple business projects – reducing redundancy. Reuse and (re)combining services allows faster project delivery and lower costs. Use what’s already there and extend what you already have (reuse on business level).</p>
<h2>Disadvantages</h2>
<p>The downside is that this flexibility comes at a price: the initial investment of setting up the design and basic services is higher, and there’s a lot of boilerplate code needed to achieve the layered structure (which can be auto generated for the most part). You also need a clear view on what you are trying to achieve; and last but not least: real sponsorship from the business to be able to succeed.</p>
<p><em>To be continued&#8230;</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/435/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/435/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/435/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=435&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/01/20/a-reference-architecture-part-2-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/01/solution12.jpg?w=227" medium="image">
			<media:title type="html">Solution structure</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/01/solution2.jpg?w=155" medium="image">
			<media:title type="html">Manager structure</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/01/solution3.jpg?w=202" medium="image">
			<media:title type="html">Agent/Utility structure</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/01/solution4.jpg" medium="image">
			<media:title type="html">Business entities</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2010/01/solution5.jpg?w=300" medium="image">
			<media:title type="html">Client projects</media:title>
		</media:content>
	</item>
		<item>
		<title>A reference architecture (Part 1)</title>
		<link>http://ludwigstuyck.wordpress.com/2010/01/12/a-reference-architecture-part-1/</link>
		<comments>http://ludwigstuyck.wordpress.com/2010/01/12/a-reference-architecture-part-1/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 14:20:35 +0000</pubDate>
		<dc:creator>Ludwig Stuyck</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[architecture WCF SOA]]></category>

		<guid isPermaLink="false">http://ludwigstuyck.wordpress.com/?p=382</guid>
		<description><![CDATA[Introduction IT and business needs have changed over the years, demanding system design to follow. In today’s tough economical conditions, there is more than ever the need to control costs and as such it is indispensable that an enterprise has to be able to respond very quickly to change with minimal effort. Traditionally projects start [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=382&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>IT and business needs have changed over the years, demanding system design to follow. In today’s tough economical conditions, there is more than ever the need to control costs and as such it is indispensable that an enterprise has to be able to respond very quickly to change with minimal effort. Traditionally projects start in the IT department, mostly without taking into account business requirements, but this just doesn’t work anymore. Instead, projects should be driven by business needs, and evidently the underlying IT solution has to support this.</p>
<p>I have built a systems architectural design template, adhering to proven SOA guidelines, to tackle this challenge.  Of course, every environment is different &#8211; and so is every design &#8211; but the idea is to have a template that uses best practises and that is extensible to your own needs. The result is a multi-layered architecture based on resources like Juval Lowy’s master class, the Web Service Software Factory guidelines, feedback from other architects and experiences with developers using this architecture.</p>
<h1>Architectural guidelines</h1>
<p>To begin, the template below visually represents the multi-layered systems architecture I have developed:</p>
<div class="mceTemp"><a href="http://ludwigstuyck.files.wordpress.com/2009/12/arch12.jpg"><img class="alignnone size-medium wp-image-415" title="Layers" src="http://ludwigstuyck.files.wordpress.com/2009/12/arch12.jpg?w=300&#038;h=133" alt="Layers" width="300" height="133" /></a></div>
<h2>Description of the layers</h2>
<p>The <strong>client layer</strong> represents all components that consume the underlying managers. It’s more than just a presentation layer, because other than graphical user interface clients this layer also contains non-visible clients that can trigger managers (for example, an email or an incoming file on an FTP server). These clients can perform non-business related validation on user input, but they don’t contain other business or data access logic.  A client can <strong>never</strong> talk directly with agents or utilities, it only talks to managers.</p>
<p>The <strong>manager layer</strong> contains the top-level coarse-grained systems, and <strong>uses the agents/utilities to delegate work</strong>:</p>
<ul>
<li>Processes:
<ul>
<li>Expose business processes</li>
<li>Typically long running (workflow) and invoked using a one-way or notification (reservation) pattern</li>
<li>Encapsulates rules particular to the business process</li>
<li>Includes transaction control using compensation</li>
<li>One process may act as a controller for another and invoke it</li>
<li>Can be stateful</li>
<li>Invoke underlying agents/utilities</li>
</ul>
</li>
<li>Activities:
<ul>
<li>Expose business activities that encapsulate calls to multiple agent and/or utilities to perform a single activity</li>
<li>Each operation scoped as a logical unit of work</li>
<li>Typically immediate request-response pattern</li>
<li>Includes rules that are common to the organization</li>
</ul>
</li>
</ul>
<p>The <strong>agent and utility layer</strong> contains the low-level granular and fine-grained components. Agents provide business-centric functional context, while utilities are more related to infrastructure functionality like logging and emailing.</p>
<p><strong>An agent:</strong></p>
<ul>
<li>Exposes business entity data</li>
<li>Typically immediate request-response pattern</li>
<li>Encapsulates data consistency rules and CRUD that are common to the entire organization</li>
<li>May invoke utilities</li>
<li>Each operation scoped as a logical unit of work</li>
</ul>
<p>There are different types of agents, for example:</p>
<ul>
<li>Proxy agent: referred to as wrapper, broker, or gateway, they act as a bridge between other members of the service-oriented system and incompatible subsystems</li>
<li>Device agent: a specialized type of proxy that stands in front of a hardware device.</li>
<li>Entity agent: exposes a single uncluttered concept that represents a business entity. They are independent from the business processes.</li>
</ul>
<p><strong> An utility : </strong></p>
<ul>
<li>Exposes shared functionality that is not specific to a business process or entity (not domain specific)</li>
<li>Typically immediate request-response</li>
<li>Does not invoke other agents</li>
</ul>
<p>The <strong>business entities layer</strong> models the real-world, global domain-specific objects, like Customers and Orders.</p>
<p>The <strong>resource layer</strong> contains resources, which can be a database, external service or any other kind of resource.</p>
<p>Important to know is that <strong>managers are service-enabled</strong>, and that <strong>agents and utilities</strong> <strong>can be service enabled</strong> but don’t have to.</p>
<h2>Communication flow</h2>
<p>Communication between clients, managers, agents, resource access layer and resource layer is only allowed from top to bottom. These are the rules:</p>
<ul>
<li>A client can consume the services from manager layer, but it cannot access the agent or resource access layer directly.</li>
<li>A component from the manager layer can consume the agent and utility layer, but it cannot access the resource access layer directly.</li>
<li>The enterprise business entities are used by manager, agent, utility and resource access layer, and so they are never exposed to the outside world.</li>
</ul>
<h2>The layers in detail</h2>
<p>The manager layer has the same structure of the agent/utility layer, except that it does not have a resource access layer. So, the manager structure is designed according to the following structure:</p>
<div id="attachment_417" class="wp-caption alignnone" style="width: 310px"><a href="http://ludwigstuyck.files.wordpress.com/2009/12/arch21.jpg"><img class="size-medium wp-image-417" title="Manager layer" src="http://ludwigstuyck.files.wordpress.com/2009/12/arch21.jpg?w=300&#038;h=173" alt="" width="300" height="173" /></a><p class="wp-caption-text">Manager layer</p></div>
<p>And the agent and utility layer is designed according to the following structure:</p>
<div id="attachment_418" class="wp-caption alignnone" style="width: 310px"><a href="http://ludwigstuyck.files.wordpress.com/2009/12/arch32.jpg"><img class="size-medium wp-image-418" title="Agent/Utility layer" src="http://ludwigstuyck.files.wordpress.com/2009/12/arch32.jpg?w=300&#038;h=213" alt="Agent/Utility layer" width="300" height="213" /></a><p class="wp-caption-text">Agent/Utility layer</p></div>
<p>Note that for the manager the service interface layer is mandatory: a manager is always exposed as a service to the clients. But for an agent or utility, the service interface layer is optional. This means that:</p>
<ul>
<li>The service business layer of a manager can use the service interface layer of an agent</li>
<li>The service business layer of a manager can use the service business layer of an agent directly (and later, if the agent is service enabled, talk to the service interface layer instead)</li>
</ul>
<h3>Service interface layer</h3>
<p>The <strong>service contract</strong> contains the interface for the service. It defines a logically and semantically related set of operations grouped on an interface and is about how a service behaves.</p>
<p>The <strong>data contract</strong> contains all data contracts that the service uses. A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. It precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged. An important characteristic is that a data contract can be reused within the service. To communicate, the client and the service do not have to share the same types, only the same data contracts.</p>
<p>The <strong>message contract</strong> contains all message contracts needed by the service. A message contract is a wrapper around the data contracts and is mostly used when you need explicit control over the format of the SOAP (Simple Object Access Protocol) message, but in the architecture we always use them for the following reasons:</p>
<ul>
<li>clarity and uniformity: use the same approach in all services</li>
<li>explicit implementation of the Request/Response pattern</li>
</ul>
<p>An important characteristic is that a message contract is designed not to be reused.</p>
<p>The <strong>fault contract</strong> contains all fault contracts. A fault contract provides a way to describe faults in a contract and mark certain types of exceptions as appropriate for transmission to the client, shielding underlying system exceptions. As a rule we use fault contracts for errors that are not part of the normal program flow, for example:</p>
<ul>
<li>void SendEmail(SendEmailRequest) throws fault exception when subject or other fields are not filled in</li>
<li>GetCustomersResponse GetCustomers() throws fault exception when underlying data source is unavailable</li>
</ul>
<p>The <strong>service adapter</strong> contains the actual implementation of the service interface. It consists of the adapter, which invokes business actions after it uses entity translators to translate between message types or data types and types required by the business actions.</p>
<h3>Service business layer</h3>
<p>The <strong>business layer</strong> takes care of enterprise business entity validation and other custom business logic.</p>
<h3>Resource access layer</h3>
<p>The <strong>resource access layer</strong> contains the repositories and resource managers. <strong>Repositories</strong> are abstractions that interact with the resource managers and provide business interfaces to the domain model: so they are coarse-grained and closer to the domain. A repository can work with an underlying resource manager or it can act as a repository to mock data (a convenient way to do unit testing). Using dependency injection techniques, the correct repositories can be invoked at runtime by specifying them in a configuration file. A <strong>resource manager</strong> is an implementer towards a specific resource, so they are fine-grained and closer to the database. They typically implement the basic CRUD (create, read, update and delete) and other data operations, and use entity translators to do the mapping between data entities and enterprise business entities.</p>
<p><strong>Rules:</strong></p>
<ul>
<li>An agent can use its repository (only one!) from the resource access layer, and can consume utilities.</li>
<li>A utility can only use its own repository (only one!) from the resource access layer.</li>
<li>A repository will mostly use only one resource manager, but in some cases it can use one or more resource managers as long as they belong to the same business context and business entities (to implement master-data relationships). Example: an OrderRepository can use a resource manager that gets partial order information from one database and another resource manager that gets another part of order information from an xml file, because the same business entity is being constructed out of it. An OrderRepository cannot use a resource manager to get for example customer information; because this does not belong to the OrderRepository’s core tasks (in this case a manager service has to be created to aggregate order and customer information).</li>
</ul>
<h2>Data flow</h2>
<p>The following diagram illustrates the request data flow:</p>
<div id="attachment_419" class="wp-caption alignnone" style="width: 310px"><a href="http://ludwigstuyck.files.wordpress.com/2009/12/arch4.jpg"><img class="size-medium wp-image-419" title="Data flow" src="http://ludwigstuyck.files.wordpress.com/2009/12/arch4.jpg?w=300&#038;h=268" alt="Data flow" width="300" height="268" /></a><p class="wp-caption-text">Data flow</p></div>
<p>Continued in <a href="http://ludwigstuyck.wordpress.com/2010/01/20/a-reference-architecture-part-2-2/">part 2</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ludwigstuyck.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ludwigstuyck.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ludwigstuyck.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ludwigstuyck.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ludwigstuyck.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ludwigstuyck.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ludwigstuyck.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ludwigstuyck.wordpress.com/382/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ludwigstuyck.wordpress.com&amp;blog=7114221&amp;post=382&amp;subd=ludwigstuyck&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ludwigstuyck.wordpress.com/2010/01/12/a-reference-architecture-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2417489f4fa437ef00401ab389ffbe9a?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">Ludwig Stuyck</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2009/12/arch12.jpg?w=300" medium="image">
			<media:title type="html">Layers</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2009/12/arch21.jpg?w=300" medium="image">
			<media:title type="html">Manager layer</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2009/12/arch32.jpg?w=300" medium="image">
			<media:title type="html">Agent/Utility layer</media:title>
		</media:content>

		<media:content url="http://ludwigstuyck.files.wordpress.com/2009/12/arch4.jpg?w=300" medium="image">
			<media:title type="html">Data flow</media:title>
		</media:content>
	</item>
	</channel>
</rss>
