<?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>.net and other musings &#187; Design Patterns</title>
	<atom:link href="http://benl.wordpress.com/category/design-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://benl.wordpress.com</link>
	<description>Ben Lovell, an agile developer living in the UK.</description>
	<lastBuildDate>Thu, 16 Jul 2009 09:43:48 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='benl.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/43c6fe283d98c1764e951cd6dfface61?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>.net and other musings &#187; Design Patterns</title>
		<link>http://benl.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://benl.wordpress.com/osd.xml" title=".net and other musings" />
		<item>
		<title>Incremental development with Monorail: Part Three</title>
		<link>http://benl.wordpress.com/2008/04/01/incremental-development-with-monorail-part-three/</link>
		<comments>http://benl.wordpress.com/2008/04/01/incremental-development-with-monorail-part-three/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 16:49:13 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ALT.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Monorail]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2008/04/01/incremental-development-with-monorail-part-three/</guid>
		<description><![CDATA[Part OnePart Two
In the last instalment we finished up with a suite of passing tests. However, we&#8217;ve yet to produce anything remotely usable so lets continue by reaching down further and driving out our services/persistence. We&#8217;ll start by writing the following test:
 
We&#8217;ve meddled with our test setup a little to introduce the MockRepository for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=296&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://benl.wordpress.com/2008/03/27/incremental-development-with-monorail/">Part One</a><br /><a href="http://benl.wordpress.com/2008/03/27/incremental-development-with-monorail-part-two/">Part Two</a></p>
<p>In the last instalment we finished up with a suite of passing tests. However, we&#8217;ve yet to produce anything remotely usable so lets continue by reaching down further and driving out our services/persistence. We&#8217;ll start by writing the following test:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/23.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="478" alt="23" src="http://benl.files.wordpress.com/2008/04/23-thumb.png?w=508&#038;h=478" width="508" border="0"></a> </p>
<p>We&#8217;ve meddled with our test setup a little to introduce the <strong>MockRepository </strong>for mocking out our <strong>PostController&#8217;s</strong> new dependency on the <strong>IBlogPostService. </strong>Our test now calls the <strong>AddPost </strong>method on our service interface and sets up the resulting <strong>AddPostResponseDto</strong>. Running the test produces a bunch of compiler whinging so we best implement the newly introduced bits:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/24.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="99" alt="24" src="http://benl.files.wordpress.com/2008/04/24-thumb.png?w=508&#038;h=99" width="508" border="0"></a></p>
<p><a href="http://benl.files.wordpress.com/2008/04/25.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="309" alt="25" src="http://benl.files.wordpress.com/2008/04/25-thumb.png?w=508&#038;h=309" width="508" border="0"></a>&nbsp; </p>
<p><a href="http://benl.files.wordpress.com/2008/04/26.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="181" alt="26" src="http://benl.files.wordpress.com/2008/04/26-thumb.png?w=508&#038;h=181" width="508" border="0"></a> </p>
<p>These are the only changes and additions we&#8217;ve made in order for the tests to compile and run. Running our test now produces the following result:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/27.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="27" alt="27" src="http://benl.files.wordpress.com/2008/04/27-thumb.png?w=508&#038;h=27" width="508" border="0"></a> </p>
<p>As we&#8217;ve yet to modify the <strong>PostController.Save(&#8230;) </strong>call to include a call the newly introduced <strong>IBlogPostService </strong>dependency. Lets go ahead and do this now:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/28.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="144" alt="28" src="http://benl.files.wordpress.com/2008/04/28-thumb.png?w=508&#038;h=144" width="508" border="0"></a> </p>
<p>We&#8217;ve now included the call to our newly introduced service and we set the <strong>responseMessage </strong>if the response is signaled as successful. Lets run our test now:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/29.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="24" alt="29" src="http://benl.files.wordpress.com/2008/04/29-thumb.png?w=495&#038;h=24" width="495" border="0"></a> </p>
<p>It works, ship it! Actually no, again we&#8217;re pretty low on <em>actual </em>functionality right now. Remember we&#8217;ve yet to actually drive out any implementation of the <strong>IBlogPostService </strong>interface as yet and I expect that the acceptance test will fail horribly since we didn&#8217;t wire up the necessary container configuration either. Lets go ahead and run the whole test suite and see what gives:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/30.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="132" alt="30" src="http://benl.files.wordpress.com/2008/04/30-thumb.png?w=508&#038;h=132" width="508" border="0"></a> </p>
<p>In the brief moments the browser appears during the test we can see the following:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/31.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="407" alt="31" src="http://benl.files.wordpress.com/2008/04/31-thumb.png?w=508&#038;h=407" width="508" border="0"></a> </p>
<p>Hmm, as I predicted earlier our application fails to run due to the lack of proper container configuration. Before we can do this we need to implement the <strong>IBlogPostService </strong>interface somewhere. We need to write a failing test to begin our foray into the implementation of a <strong>BlogPostService</strong>:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/32.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="124" alt="32" src="http://benl.files.wordpress.com/2008/04/32-thumb.png?w=508&#038;h=124" width="508" border="0"></a> </p>
<p>Lets create the <strong>BlogPostService </strong>only performing the steps necessary to pass the test above:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/33.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="184" alt="33" src="http://benl.files.wordpress.com/2008/04/33-thumb.png?w=508&#038;h=184" width="508" border="0"></a> </p>
<p>Run the test:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/34.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="19" alt="34" src="http://benl.files.wordpress.com/2008/04/34-thumb.png?w=508&#038;h=19" width="508" border="0"></a> </p>
<p>Now we have a working <strong>BlogPostService </strong>we can now wire up our container configuration to pass the acceptance test:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/35.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="86" alt="35" src="http://benl.files.wordpress.com/2008/04/35-thumb.png?w=508&#038;h=86" width="508" border="0"></a> </p>
<p>Now running the full suite of tests produces the following:</p>
<p><a href="http://benl.files.wordpress.com/2008/04/36.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="36" alt="36" src="http://benl.files.wordpress.com/2008/04/36-thumb.png?w=508&#038;h=36" width="508" border="0"></a> </p>
<p>Our tests pass!</p>
<p>That&#8217;s it for this post. I&#8217;ve checked in the latest changes to the repository. In the next post we&#8217;ll continue our efforts and begin to implement validation on our screen-bound DTO&#8217;s.</p>
<p>Google code hosted project: <a title="http://code.google.com/p/mr-blogengine/" href="http://code.google.com/p/mr-blogengine/">http://code.google.com/p/mr-blogengine/</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/296/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/296/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=296&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2008/04/01/incremental-development-with-monorail-part-three/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/23-thumb.png" medium="image">
			<media:title type="html">23</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/24-thumb.png" medium="image">
			<media:title type="html">24</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/25-thumb.png" medium="image">
			<media:title type="html">25</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/26-thumb.png" medium="image">
			<media:title type="html">26</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/27-thumb.png" medium="image">
			<media:title type="html">27</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/28-thumb.png" medium="image">
			<media:title type="html">28</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/29-thumb.png" medium="image">
			<media:title type="html">29</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/30-thumb.png" medium="image">
			<media:title type="html">30</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/31-thumb.png" medium="image">
			<media:title type="html">31</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/32-thumb.png" medium="image">
			<media:title type="html">32</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/33-thumb.png" medium="image">
			<media:title type="html">33</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/34-thumb.png" medium="image">
			<media:title type="html">34</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/35-thumb.png" medium="image">
			<media:title type="html">35</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/04/36-thumb.png" medium="image">
			<media:title type="html">36</media:title>
		</media:content>
	</item>
		<item>
		<title>Incremental development with Monorail</title>
		<link>http://benl.wordpress.com/2008/03/27/incremental-development-with-monorail/</link>
		<comments>http://benl.wordpress.com/2008/03/27/incremental-development-with-monorail/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 00:09:37 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ALT.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Monorail]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2008/03/27/incremental-development-with-monorail/</guid>
		<description><![CDATA[EDIT: This is hosted in a google code project accessible from here: http://code.google.com/p/mr-blogengine/
&#160;
This is the first of a series of posts I&#8217;m penning where I&#8217;ll be incrementally developing a basic blog engine running on the Castle trunk and developed wholly test first.
Each new feature or addition will be described by simple narrative, followed by some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=164&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>EDIT: </strong>This is hosted in a google code project accessible from here: <a title="http://code.google.com/p/mr-blogengine/" href="http://code.google.com/p/mr-blogengine/">http://code.google.com/p/mr-blogengine/</a></p>
<p>&nbsp;</p>
<p>This is the first of a series of posts I&#8217;m penning where I&#8217;ll be incrementally developing a basic blog engine running on the Castle trunk and developed wholly test first.</p>
<p>Each new feature or addition will be described by simple narrative, followed by some testing/coding from the UI (or controller in this case) down to the database.</p>
<p>I&#8217;ll be using much of the Castle stack goodness including Monorail, Windsor and ActiveRecord. Unit testing with Mbunit and acceptance testing with Watin.</p>
<p>My aim with this series of posts is to demonstrate the power of the Castle stack, combined with TDD and the slow, incremental addition of features. After each post I&#8217;ll check in my latest changes which will after a clean build will result in a fully working system.</p>
<p><a href="http://benl.files.wordpress.com/2008/03/project-structure1.png"><img style="border-width:0;" height="562" alt="project-structure" src="http://benl.files.wordpress.com/2008/03/project-structure-thumb.png?w=285&#038;h=562" width="285" align="right" border="0"></a> </p>
<p>I&#8217;ve completed a small amount of scaffolding up-front for brevity:</p>
<ul>
<li>Castle built from trunk
<li>Solution and project structure
<li>Basic configuration of Monorail and Windsor </li>
</ul>
<p>As you can see from the right, our solution consists of three projects. The core project will hold our domain model, interfaces, services and application code. There is a test project for both our unit tests and acceptance tests, and finally we have the web application project holding our controllers, views and static content. I&#8217;ve put together a basic layout and stylesheet that serve our needs for now. This will be added to as our blog engine matures.</p>
<p>Although we have no concrete examples as yet, the controllers, services, facilities and configuration properties are configured through Windsor XML configuration files in the web project. We&#8217;re running on a Castle build I ran locally after checking out the trunk some point over the last couple of days.</p>
<p>It will be interesting to see how our initial design adapts as required when features are piled on during the later stages of development. I&#8217;ve not got any specific plans on how long this series will go on for although I am considering moving my blog away from WordPress and will most likely host under the very blog engine I&#8217;ll be creating. Good times! Anyway enough of this, lets move on to the first iteration.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Iteration 1: Create a Post</h2>
<p>For this iteration we will build our first cut at the blog post authoring screen. This comprises a very basic form allowing the author to specify the title, short description and full content of the post. I think you&#8217;ll agree that what we&#8217;re building in this iteration won&#8217;t serve as a fully powered blog engine any time soon, but lets restate our initial aim here: to <strong>incrementally </strong>build and adapt our system as new requirements and features emerge. With that said, lets get on to building our first feature!</p>
<p>Our first test:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/17.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="221" alt="1" src="http://benl.files.wordpress.com/2008/03/1-thumb3.png?w=508&#038;h=221" width="508" border="0"></a> </p>
<p>From our basic requirement we&#8217;re now driving out the <strong>PostController. </strong>This test simply gets our controller into a good state for testing, handily provided by Monorail&#8217;s <strong>BaseControllerTest</strong> and our first test method asserts that when the <strong>Add </strong>action is called on our controller the correct view is rendered. As you can see from the grab above there is a lot of red code. Resharper is highlighting the members we&#8217;ve yet to implement. I attempted to run this test but the compiler chokes. Time to do what we need to pass this test:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/22.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="152" alt="2" src="http://benl.files.wordpress.com/2008/03/2-thumb1.png?w=348&#038;h=152" width="348" border="0"></a> </p>
<p>Well that was simple enough. Lets run our test and see the result:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/33.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="89" alt="Test Results" src="http://benl.files.wordpress.com/2008/03/3-thumb2.png?w=508&#038;h=89" width="508" border="0"></a> </p>
<p>As expected, the test now passes. However, there are some serious issues with our controller and the related Monorail configuration:</p>
<ol>
<li>The controller has no associated layout.
<li>We&#8217;ve yet to create the requisite view: <strong>Add.vm</strong>.
<li>We&#8217;ve not added the Windsor XML configuration for our controller. </li>
</ol>
<p>Before we can do anything to remedy the issues above we&#8217;ll need to write a failing test. I&#8217;m going to use Watin to create a test which flexes Monorail a little more. Currently our only test relies heavily on most of the controller dependencies being stubbed/mocked out by the <strong>BaseControllerTest </strong>class. We&#8217;ll need to test through the browser to ensure our controller and view/layout are wired up correctly:</p>
<p>&nbsp;<a href="http://benl.files.wordpress.com/2008/03/43.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="198" alt="4" src="http://benl.files.wordpress.com/2008/03/4-thumb2.png?w=508&#038;h=198" width="508" border="0"></a> </p>
<p>As you can see above we&#8217;ve crafted a very simplistic test which asserts that the text &#8220;<strong>Ben Lovell&#8217;s Blog&#8221; </strong>is found in the browser at the specified URL. Note also that our test assumes the application is running at localhost on port 16489. I&#8217;ve configured this in the web application properties so we just need to ensure that the VSNET web development server is running on this port for our application. Lets run the test:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/51.png"><img style="border-width:0;" height="40" alt="5" src="http://benl.files.wordpress.com/2008/03/5-thumb.png?w=447&#038;h=40" width="447" border="0"></a> </p>
<p>As expected it fails. To pass this test we need to perform the three steps mentioned earlier. To do this we first add the <strong>Layout </strong>attribute to the controller and specify the <strong>default </strong>layout, the contents of which are shown here:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/73.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="286" alt="7" src="http://benl.files.wordpress.com/2008/03/7-thumb2.png?w=508&#038;h=286" width="508" border="0"></a> </p>
<p>Next we create an empty view: <strong>Add.vm</strong> in the <strong>views/post</strong> folder, and finally we wire up the XML configuration for our controller in the <strong>controllers.config </strong>file as shown below:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/64.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="67" alt="6" src="http://benl.files.wordpress.com/2008/03/6-thumb3.png?w=508&#038;h=67" width="508" border="0"></a> </p>
<p>Lets try and run the test now:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/81.png"><img style="border-width:0;" height="19" alt="8" src="http://benl.files.wordpress.com/2008/03/8-thumb.png?w=378&#038;h=19" width="378" border="0"></a> </p>
<p>Now we&#8217;re making progress! Lets extend our test a little more now. This time we will find the title, description and content fields, enter some values and submit the form. Asserting that the confirmation message was displayed telling the user their post was saved:</p>
<p>&nbsp;<a href="http://benl.files.wordpress.com/2008/03/94.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="274" alt="9" src="http://benl.files.wordpress.com/2008/03/9-thumb3.png?w=508&#038;h=274" width="508" border="0"></a> </p>
<p>A few things have changed here: we&#8217;ve altered the naming of the test to clarify intent, and as mentioned previously our test will enter some values into our form fields and submit the form. Our last assertion is checking that the correct confirmation message is displayed. Now we could argue that the setting of the description and content is superfluous in this test as the outcomes aren&#8217;t asserted. But, the effort required to implement those fields is minimal and highly unlikely to impact on any existing code/tests (i.e. none!).</p>
<p>Lets run the test and see the outcome:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/104.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="28" alt="10" src="http://benl.files.wordpress.com/2008/03/10-thumb3.png?w=508&#038;h=28" width="508" border="0"></a> </p>
<p>Our test complains that the &#8220;Add Post&#8221; text was not found. Lets go and fiddle with our view:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/121.png"><img style="border-width:0;" height="61" alt="12" src="http://benl.files.wordpress.com/2008/03/12-thumb.png?w=269&#038;h=61" width="269" border="0"></a> </p>
<p>Good to go, lets run the test:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/114.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="32" alt="11" src="http://benl.files.wordpress.com/2008/03/11-thumb3.png?w=508&#038;h=32" width="508" border="0"></a> </p>
<p>Hmm, the first two asserts are passing but now we&#8217;re failing on unfound input: <strong>post.Title</strong>. Time to add the form and fields to the view, we&#8217;re going to make a slight jump and include the description and content inputs in our view also:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/133.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="375" alt="13" src="http://benl.files.wordpress.com/2008/03/13-thumb2.png?w=508&#038;h=375" width="508" border="0"></a> </p>
<p>Re run the test:</p>
<p><a href="http://benl.files.wordpress.com/2008/03/144.png"><img style="border-right:0;border-top:0;border-left:0;border-bottom:0;" height="24" alt="14" src="http://benl.files.wordpress.com/2008/03/14-thumb3.png?w=508&#038;h=24" width="508" border="0"></a> </p>
<p>It fails as we have yet to create the <strong>save </strong>action on the controller, and also the nonexistent action doesn&#8217;t display the required confirmation&#8230; For obvious reasons.</p>
<p>At this stage I&#8217;m going to wrap this up for now. Part two will follow over the next couple of days. Stay tuned!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/164/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/164/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/164/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/164/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/164/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=164&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2008/03/27/incremental-development-with-monorail/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/project-structure-thumb.png" medium="image">
			<media:title type="html">project-structure</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/1-thumb3.png" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/2-thumb1.png" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/3-thumb2.png" medium="image">
			<media:title type="html">Test Results</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/4-thumb2.png" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/5-thumb.png" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/7-thumb2.png" medium="image">
			<media:title type="html">7</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/6-thumb3.png" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/8-thumb.png" medium="image">
			<media:title type="html">8</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/9-thumb3.png" medium="image">
			<media:title type="html">9</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/10-thumb3.png" medium="image">
			<media:title type="html">10</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/12-thumb.png" medium="image">
			<media:title type="html">12</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/11-thumb3.png" medium="image">
			<media:title type="html">11</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/13-thumb2.png" medium="image">
			<media:title type="html">13</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2008/03/14-thumb3.png" medium="image">
			<media:title type="html">14</media:title>
		</media:content>
	</item>
		<item>
		<title>Front-end DTO&#8217;s</title>
		<link>http://benl.wordpress.com/2008/03/11/front-end-dtos/</link>
		<comments>http://benl.wordpress.com/2008/03/11/front-end-dtos/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 14:16:25 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[ALT.NET]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Monorail]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2008/03/11/front-end-dtos/</guid>
		<description><![CDATA[An interesting discussion was brought up in one of the ALT.NET groups regarding the use of DTO&#8217;s in the presentation layer that I had to chime in on.
I&#8217;m a strong advocate of message passing from the UI to your services for several reasons:

Test driving from the top-down is my favoured approach when developing web applications. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=146&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>An interesting discussion was brought up in one of the ALT.NET groups regarding the use of DTO&#8217;s in the presentation layer that I had to chime in on.</p>
<p>I&#8217;m a strong advocate of message passing from the UI to your services for several reasons:</p>
<ol>
<li>Test driving from the top-down is my favoured approach when developing web applications. I&#8217;ll start by writing a failing test for my controller (you should know by now I use Monorail <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Then I&#8217;ll stub out any dependencies, these usually being service interfaces which accept and return simple DTO&#8217;s with absolutely no behaviour. Stubbing out the services allows you to return dummy data very early on in your development. The nice thing about this approach is you can get a working UI together very quickly and then drive out the development of each layer until you hit your domain model. From which point you can then wire-up your real service and repository implementations and satisfy your acceptance tests end-to-end. Now I&#8217;m not suggesting that this approach isn&#8217;t possible without DTO&#8217;s but it makes it a heck lot easier in my experience.</li>
<li>DDD aggregates by their very nature are composed of behaviours you don&#8217;t want to pass into your UI. Using DTO&#8217;s for binding into your UI keeps things nice and lightweight. Cohesion is high as the DTO&#8217;s are created for a very specific purpose, usually to satisfy a particular screen or UI workflow.</li>
<li>I had made the rather nebulous statement that the use of DTO&#8217;s insulates your UI against changes in your domain model. Quite rightly somebody replied saying that this was all relative and there are many means to insulate against change. Of course, I wholeheartedly agree but in my defence I was replying to the OP from my iPhone. Now for me to explain this a little&#8230; Unless you&#8217;re using query projections (a la NHibernate) you&#8217;ll be mapping from your domain entities to specific DTO&#8217;s using some kind of mapper class. Your mapper probably depends on the interfaces of your particular domain entities and the implementation of your DTO&#8217;s. I say <em>implementation</em> as I drive out the mapping using state-based testing, which of course makes perfect sense when mapping from one state to another! Using DTO&#8217;s means our controller has a nice seam between itself and the services through their interfaces thus the controller (read: UI) has no knowledge of the domain model at all. Any changes to the domain model are catered for by changing the mapper specific to the affected messages. I won&#8217;t get into versioning messages, mainly because I haven&#8217;t got the time or inclination <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>I&#8217;ve always thought (and I read this somewhere I think, but can&#8217;t remember where) that a sign of a well designed architecture, among other things of course, is the ability to replace the UI and have everything function correctly. Now it was probably more poetic than that but essentially what this means is your UI should have absolutely zero dependencies on anything below your service interfaces. Using DTO&#8217;s and message passing means the only work your controllers are doing is scraping the request, passing your message to a service and binding the response. I&#8217;ve demonstrated this in systems I&#8217;ve developed by providing an API (which can be considered another UI if you squint a little and look sideways) which is comprised of exactly the same service calls and DTO&#8217;s my web UI is using.</li>
<li>My last point isn&#8217;t specifically tied to the use of DTO&#8217;s but more based around messaging architecture in general&#8230; What this gives me from the very beginning (i.e. the first test) is a nice basis for distributing my architecture. Our services can be hosted on an application server separately from our web application&nbsp; or preferably located transparently via a message bus which brings in a whole heap of nice side-effects&#8230; </li>
</ol>
<p>So in summary you can see I&#8217;m a big fan of the domain model in my services, mapping to and from DTO&#8217;s in my UI. What is your favoured approach?</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/146/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/146/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/146/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/146/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/146/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=146&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2008/03/11/front-end-dtos/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
		<item>
		<title>Screen casts coming soon</title>
		<link>http://benl.wordpress.com/2008/01/18/screen-casts-coming-soon/</link>
		<comments>http://benl.wordpress.com/2008/01/18/screen-casts-coming-soon/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 23:07:43 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Monorail]]></category>
		<category><![CDATA[Screencasts]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2008/01/18/screen-casts-coming-soon/</guid>
		<description><![CDATA[My plan is to build a basic blogging engine using Castle Monorail, Windsor, ActiveRecord and developed with DDD &#38; TDD. I&#8217;ll screencast the whole procedure from start to finish, outlining the basic story or stories for each screencast episode and then go ahead and implement those stories.
Due to the (potential) size of this I&#8217;ll no [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=145&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My plan is to build a basic blogging engine using Castle Monorail, Windsor, ActiveRecord and developed with DDD &amp; TDD. I&#8217;ll screencast the whole procedure from start to finish, outlining the basic story or stories for each screencast <em>episode</em> and then go ahead and implement those stories.
<p>Due to the (potential) size of this I&#8217;ll no doubt split this up over many screencasts &#8211; probably weighing in at around an hour or so per piece. Production values will be conspicuously low of course and the screencasts are not necessarily meant to serve as an educational tool, more a window into my usage of tools &amp; techniques.
<p>I&#8217;ll spike out the solution bootstrapping and structure before the first screencast rather than bore you with the requisite stuff. Anyway, expect the first bunch of stories to appear some point early next week&#8230; </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/145/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/145/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/145/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/145/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/145/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=145&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2008/01/18/screen-casts-coming-soon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
		<item>
		<title>Dependency injection with Monorail and Windsor</title>
		<link>http://benl.wordpress.com/2007/06/27/dependency-injection-with-monorail-and-windsor/</link>
		<comments>http://benl.wordpress.com/2007/06/27/dependency-injection-with-monorail-and-windsor/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 16:06:50 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Windsor]]></category>
		<category><![CDATA[mono-rail]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2007/06/27/dependency-injection-with-monorail-and-windsor/</guid>
		<description><![CDATA[Dependency Injection (or IoC) is a&#160;practice I apply when designing software. It enables enforcement of the Single Responsibility Principle&#160;and also has the added&#160;side effect of producing more testable code.
Scott Bellware has posted an excellent write-up on dependency patterns and it got me thinking about my favoured approach with dependency injection and&#160;how the&#160;Castle Windsor container provides [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=100&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.martinfowler.com/articles/injection.html" target="_blank">Dependency Injection (or IoC)</a> is a&nbsp;practice I apply when designing software. It enables enforcement of the Single Responsibility Principle&nbsp;and also has the added&nbsp;side effect of producing more testable code.</p>
<p><a href="http://codebetter.com/blogs/scott.bellware/default.aspx" target="_blank">Scott Bellware</a> has posted an excellent <a href="http://codebetter.com/blogs/scott.bellware/archive/2007/06/26/164729.aspx" target="_blank">write-up on dependency patterns</a> and it got me thinking about my favoured approach with dependency injection and&nbsp;how the&nbsp;<a href="http://castleproject.org/container/index.html" target="_blank">Castle Windsor</a> container provides that&nbsp;for us. I favour constructor based DI as it enforces the fact that your class <strong>must </strong>be wired up during initialisation. It makes your dependencies highly visible and as Scott mentions &#8211; goes some way to producing a self-documenting API. </p>
<p>Some of the common&nbsp;alternatives, or&nbsp;perhaps complimentary&nbsp;approaches include resolving dependencies from the container or service locator&nbsp;hidden in the constructor (dirty), or the provision of property setters for your dependent interfaces. Of course providing getters (or at least public getters) is a no-no as you would be exposing your dependencies to consumers thus violating encapsulation. But I guess this goes without saying?</p>
<p>Thankfully, <a href="http://castleproject.org/monorail/index.html" target="_blank">Monorail</a> controllers and their dependencies&nbsp;can be wired up using constructor based DI&nbsp;via <a href="http://wiki.castleproject.org/index.php/MonoRail:How_to:_Enable_Windsor_integration" target="_blank">RailsFacility</a> and Windsor integration. Take the following example:</p>
<p><a href="http://benl.files.wordpress.com/2007/06/dependencies.png"><img style="border-width:0;" height="172" alt="dependencies" src="http://benl.files.wordpress.com/2007/06/dependencies-thumb.png?w=240&#038;h=172" width="240" border="0"></a> </p>
<p><em>ContactController </em>in the diagram above is a simple&nbsp;Monorail controller that&nbsp;depends on the <em>IContactService </em>to carry out most of&nbsp;its work. Stemming from there the IContactService implementation has dependencies on <em>IContactRepository </em>and an external library (from <a href="http://www.google.co.uk/url?sa=t&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fnspectre.sourceforge.net%2F&amp;ei=wIqCRpqfDI2w0wT_mcThDA&amp;usg=AFQjCNEuVcjMocxJu8j8uD9feySLVQYNKA&amp;sig2=IyZ7tbJb0MNNWW6pif8M-A" target="_blank">NSpectre</a>) interface <em>IValidatorFactory</em> which is created using the Windsor factory facility and some custom factory code, but more on that later&#8230; As you can see from the model, the dependencies are injected via constructor arguments.</p>
<p>Using the RailsFacility is fairly simple, rather than me explaining it I&#8217;ll point you to the <a href="http://wiki.castleproject.org/index.php/MonoRail:How_to:_Enable_Windsor_integration" target="_blank">docs here</a>. Once you&#8217;ve got the facility and container set up, you simple declare your controllers and their dependent components via configuration: </p>
<pre style="width:441px;height:126px;"><span style="color:rgb(0,0,255);">&lt;</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);"> </span><span style="color:rgb(255,0,0);">id</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">contact.controller</span>"<span style="color:rgb(0,0,255);"> </span><span style="color:rgb(255,0,0);">type</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Controllers.ContactController, Campaigns.Controllers</span>"<span style="color:rgb(0,0,255);">&gt;
      &lt;</span><span style="color:rgb(163,21,21);">parameters</span><span style="color:rgb(0,0,255);">&gt;
        &lt;</span><span style="color:rgb(163,21,21);">mailTo</span><span style="color:rgb(0,0,255);">&gt;</span>benjamin.lovell@gmail.com<span style="color:rgb(0,0,255);">&lt;/</span><span style="color:rgb(163,21,21);">mailTo</span><span style="color:rgb(0,0,255);">&gt;
        &lt;</span><span style="color:rgb(163,21,21);">subject</span><span style="color:rgb(0,0,255);">&gt;</span>Contact message from Website<span style="color:rgb(0,0,255);">&lt;/</span><span style="color:rgb(163,21,21);">subject</span><span style="color:rgb(0,0,255);">&gt;
      &lt;/</span><span style="color:rgb(163,21,21);">parameters</span><span style="color:rgb(0,0,255);">&gt;
    &lt;/</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>I&#8217;ve explicitly declared some of the required values for the <em>ContactController</em> constructor above. Just as reminder the signature for <em>ContactController</em> &nbsp;constructor:</p>
<pre style="width:441px;height:39px;"><span style="color:rgb(0,0,255);">public</span> ContactController(<span style="color:rgb(43,145,175);">IContactService</span> contactService, <span style="color:rgb(0,0,255);">string</span> mailTo, <span style="color:rgb(0,0,255);">string</span> subject)</pre>
<p>When the <em>ContactController&nbsp;</em>is wired up by windsor the&nbsp;<em>IContactService contactService&nbsp;</em>argument&nbsp;is resolved to the following service configured in my components.config file:</p>
<pre style="width:442px;height:93px;"><span style="color:rgb(0,0,255);">&lt;</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);"> </span><span style="color:rgb(255,0,0);">id</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">contact-service</span>"
<span style="color:rgb(0,0,255);">               </span><span style="color:rgb(255,0,0);">service</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Core.IContactService, Campaigns.Core</span>"
<span style="color:rgb(0,0,255);">               </span><span style="color:rgb(255,0,0);">type</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Services.ContactService, Campaigns.Services</span>"<span style="color:rgb(0,0,255);">&gt;
    &lt;/</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);">&gt;</span></pre>
<p>Of course, <em>ContactService </em>also joins in the fun and has its dependencies injected via the same means:</p>
<pre style="width:440px;height:83px;"><span style="color:rgb(0,0,255);">&lt;</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);"> </span><span style="color:rgb(255,0,0);">id</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">contact-repository</span>"
<span style="color:rgb(0,0,255);">               </span><span style="color:rgb(255,0,0);">service</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Core.IContactRepository, Campaigns.Core</span>"
<span style="color:rgb(0,0,255);">               </span><span style="color:rgb(255,0,0);">type</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Repository.ContactRepository, Campaigns.Repository</span>"<span style="color:rgb(0,0,255);"> /&gt;</span></pre>
<p>Windsor detects that the <em>ContactService </em>constructor takes a <em>IContactRepository </em>argument and resolves this automatically. </p>
<p>Now for the keen-eyed among you, and going back to my point earlier regarding the <em>IValidatorFactory </em>dependency&#8230; This is resolved using the natty Windsor factory facility, the <a href="http://blog.bittercoder.com/PermaLink,guid,07925133-ae33-41dd-bc50-2b49a5434e19.aspx" target="_blank">best explanation of which is here</a>. In my configuration I state that <em>IValidatorFactory </em>dependencies should be resolved via my custom factory code: </p>
<pre style="width:447px;height:211px;"><span style="color:rgb(0,0,255);">using</span> NSpectre.Core;
<span style="color:rgb(0,0,255);">using</span> NSpectre.Core.Configuration;
<span style="color:rgb(0,0,255);">using</span> NSpectre.Core.Implementation;

<span style="color:rgb(0,0,255);">namespace</span> Campaigns.Core
{
    <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>    <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Factory for NSpectre validators
</span>    <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>    <span style="color:rgb(0,0,255);">public</span> <span style="color:rgb(0,0,255);">class</span> <span style="color:rgb(43,145,175);">NSpectreFactory</span> : <span style="color:rgb(43,145,175);">INSpectreFactory
</span>    {
<span style="color:rgb(0,0,255);">        #region</span> Fields

        <span style="color:rgb(0,0,255);">private</span> <span style="color:rgb(0,0,255);">readonly</span> <span style="color:rgb(0,0,255);">string</span> xmlEmbeddedResourcePath;
        <span style="color:rgb(0,0,255);">private</span> <span style="color:rgb(0,0,255);">readonly</span> <span style="color:rgb(0,0,255);">bool</span> saveGeneratedCode = <span style="color:rgb(0,0,255);">false</span>;
        <span style="color:rgb(0,0,255);">private</span> <span style="color:rgb(0,0,255);">readonly</span> <span style="color:rgb(0,0,255);">string</span> path;

<span style="color:rgb(0,0,255);">        #endregion

        #region</span> Constructors

        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Initialises the factory with the embedded resource path.
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;param name="xmlEmbeddedResourcePath"&gt;</span><span style="color:rgb(0,128,0);">The path to the embedded resource.</span><span style="color:rgb(128,128,128);">&lt;/param&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;param name="saveGeneratedCode"&gt;</span><span style="color:rgb(0,128,0);">Save the generated code</span><span style="color:rgb(128,128,128);">&lt;/param&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;param name="path"&gt;</span><span style="color:rgb(0,128,0);">The path to save the code to</span><span style="color:rgb(128,128,128);">&lt;/param&gt;
</span>        <span style="color:rgb(0,0,255);">public</span> NSpectreFactory(<span style="color:rgb(0,0,255);">string</span> xmlEmbeddedResourcePath, <span style="color:rgb(0,0,255);">bool</span> saveGeneratedCode, <span style="color:rgb(0,0,255);">string</span> path) : <span style="color:rgb(0,0,255);">this</span>(xmlEmbeddedResourcePath)
        {
            <span style="color:rgb(0,0,255);">this</span>.saveGeneratedCode = saveGeneratedCode;
            <span style="color:rgb(0,0,255);">this</span>.path = path;
        }

        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Initialises the factory with the path to the NSpectre configuration embedded resource.
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;param name="xmlEmbeddedResourcePath"&gt;&lt;/param&gt;
</span>        <span style="color:rgb(0,0,255);">public</span> NSpectreFactory(<span style="color:rgb(0,0,255);">string</span> xmlEmbeddedResourcePath)
        {
            <span style="color:rgb(0,0,255);">this</span>.xmlEmbeddedResourcePath = xmlEmbeddedResourcePath;
        }

<span style="color:rgb(0,0,255);">        #endregion

        #region</span> Properties

        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Gets the path to the configuration embedded resource.
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>        <span style="color:rgb(0,0,255);">public</span> <span style="color:rgb(0,0,255);">string</span> XmlEmbeddedResourcePath
        {
            <span style="color:rgb(0,0,255);">get</span> { <span style="color:rgb(0,0,255);">return</span> xmlEmbeddedResourcePath; }
        }

        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Gets a flag indicating whether NSpectre should save the generated code.
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>        <span style="color:rgb(0,0,255);">public</span> <span style="color:rgb(0,0,255);">bool</span> SaveGeneratedCode
        {
            <span style="color:rgb(0,0,255);">get</span> { <span style="color:rgb(0,0,255);">return</span> saveGeneratedCode; }
        }

        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Gets the path to save the generated code to.
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>        <span style="color:rgb(0,0,255);">public</span> <span style="color:rgb(0,0,255);">string</span> Path
        {
            <span style="color:rgb(0,0,255);">get</span> { <span style="color:rgb(0,0,255);">return</span> path; }
        }

<span style="color:rgb(0,0,255);">        #endregion

        #region</span> Methods

        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> Creates the validator factory
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;/summary&gt;
</span>        <span style="color:rgb(128,128,128);">///</span><span style="color:rgb(0,128,0);"> </span><span style="color:rgb(128,128,128);">&lt;returns&gt;</span><span style="color:rgb(0,128,0);">The validator factory, initialised</span><span style="color:rgb(128,128,128);">&lt;/returns&gt;
</span>        <span style="color:rgb(0,0,255);">public</span> <span style="color:rgb(43,145,175);">IValidatorFactory</span> CreateFactory()
        {
            <span style="color:rgb(43,145,175);">IConfigurationReader</span> reader = <span style="color:rgb(0,0,255);">new</span> <span style="color:rgb(43,145,175);">EmbbeddedXmlResourceConfigurationReader</span>(xmlEmbeddedResourcePath, <span style="color:rgb(0,0,255);">new</span> <span style="color:rgb(43,145,175);">NullLogger</span>());
            <span style="color:rgb(43,145,175);">Initialiser</span> initialiser = <span style="color:rgb(0,0,255);">new</span> <span style="color:rgb(43,145,175);">Initialiser</span>();

            <span style="color:rgb(0,0,255);">if</span> (SaveGeneratedCode)
                <span style="color:rgb(0,0,255);">return</span> initialiser.CreateValidatorFactory(reader, saveGeneratedCode, path);
            <span style="color:rgb(0,0,255);">else
</span>                <span style="color:rgb(0,0,255);">return</span> initialiser.CreateValidatorFactory(reader);
        }

<span style="color:rgb(0,0,255);">        #endregion
</span>    }
}</pre>
<p>The custom factory is hooked up using the following configuration:</p>
<pre style="width:447px;height:208px;"><span style="color:rgb(0,0,255);">&lt;</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);"> </span><span style="color:rgb(255,0,0);">id</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">nspectre.factory</span>"<span style="color:rgb(0,0,255);">
               </span><span style="color:rgb(255,0,0);">service</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Core.INSpectreFactory, Campaigns.Core</span>"<span style="color:rgb(0,0,255);">
               </span><span style="color:rgb(255,0,0);">type</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">Campaigns.Core.NSpectreFactory, Campaigns.Core</span>"<span style="color:rgb(0,0,255);">&gt;
      &lt;</span><span style="color:rgb(163,21,21);">parameters</span><span style="color:rgb(0,0,255);">&gt;
        &lt;</span><span style="color:rgb(163,21,21);">xmlEmbeddedResourcePath</span><span style="color:rgb(0,0,255);">&gt;</span>Campaigns.Core.Model.NSpectreValidations.xml, Campaigns.Core<span style="color:rgb(0,0,255);">&lt;/</span><span style="color:rgb(163,21,21);">xmlEmbeddedResourcePath</span><span style="color:rgb(0,0,255);">&gt;
      &lt;/</span><span style="color:rgb(163,21,21);">parameters</span><span style="color:rgb(0,0,255);">&gt;
    &lt;/</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);">&gt;

    &lt;</span><span style="color:rgb(163,21,21);">component</span><span style="color:rgb(0,0,255);"> </span><span style="color:rgb(255,0,0);">id</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">nspectre.default</span>"<span style="color:rgb(0,0,255);">
               </span><span style="color:rgb(255,0,0);">type</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">NSpectre.Core.IValidatorFactory, NSpectre.Core</span>"
<span style="color:rgb(0,0,255);">               </span><span style="color:rgb(255,0,0);">factoryId</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">nspectre.factory</span>"
<span style="color:rgb(0,0,255);">               </span><span style="color:rgb(255,0,0);">factoryCreate</span><span style="color:rgb(0,0,255);">=</span>"<span style="color:rgb(0,0,255);">CreateFactory</span>"<span style="color:rgb(0,0,255);"> /&gt;</span></pre>
<p>You really notice the effectiveness of this approach when adding new controllers to your project. You simply add the controller code, define its dependencies in the constructor and add the configuration for the controller to your controllers.config file and everything is resolved and injected for you at runtime. Very nice indeed, I&#8217;m sure you will agree!</p>
<p>Testing is made easy by providing dynamic mocks. To make this an even nicer experience take a look at the <a href="http://blog.eleutian.com/CommentView,guid,762249da-e25a-4503-8f20-c6d59b1a69bc.aspx" target="_blank">AutoMockingContainer</a> from the nice folks at <a href="http://blog.eleutian.com/" target="_blank">Eleutian</a>!</p>
<p>To wrap up I have to say: Castle really does kick the llama&#8217;s ass. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/100/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/100/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/100/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/100/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/100/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=100&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2007/06/27/dependency-injection-with-monorail-and-windsor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>

		<media:content url="http://benl.files.wordpress.com/2007/06/dependencies-thumb.png" medium="image">
			<media:title type="html">dependencies</media:title>
		</media:content>
	</item>
		<item>
		<title>Monorail services</title>
		<link>http://benl.wordpress.com/2007/06/23/monorail-services/</link>
		<comments>http://benl.wordpress.com/2007/06/23/monorail-services/#comments</comments>
		<pubDate>Sat, 23 Jun 2007 20:45:41 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Monorail]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2007/06/23/monorail-services/</guid>
		<description><![CDATA[The monorail pipeline is modeled around a key set of services. This allows a certain amount of flexibility when acquiring resources or using dependent services such as email sending, scaffolding support, controller factories and the like.
Upon initialization of the monorail framework these services are defaulted to monorail provided implementations based on the existence (or non-existence) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=97&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The monorail pipeline is modeled around a key set of services. This allows a certain amount of flexibility when acquiring resources or using dependent services such as email sending, scaffolding support, controller factories and the like.</p>
<p>Upon initialization of the monorail framework these services are defaulted to monorail provided implementations based on the existence (or non-existence) of service configuration in your web.config file.</p>
<p>This is particularly handy for mocking out infrastructure during automated acceptance testing. Emailing is a good example of when you might want to do such a thing. To provide a mock service for email sending you simply add the following into your web.config:</p>
<pre style="width:509px;height:114px;"><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">services</span><span style="color:#0000ff;">&gt;
  &lt;</span><span style="color:#a31515;">service
</span><span style="color:#0000ff;">        </span><span style="color:#ff0000;">id</span><span style="color:#0000ff;">=</span>"<span style="color:#0000ff;">EmailSender</span>"
<span style="color:#0000ff;">        </span><span style="color:#ff0000;">type</span><span style="color:#0000ff;">=</span>"<span style="color:#0000ff;">Castle.Components.Common.EmailSender.Mock.MockEmailSender, Castle.Components.Common.EmailSender</span>"<span style="color:#0000ff;"> /&gt;
&lt;/</span><span style="color:#a31515;">services</span><span style="color:#0000ff;">&gt;</span></pre>
<p>You could of course provide your own mock implementations if necessary.</p>
<p>To provide dynamic mocking for unit testing you should mock out the <em>RailsEngineContext</em> and return an <em>IEmailSender</em> implementation (or dynamic mock) by setting up an expected return on the <em>IRailsEngineContext.GetService</em> call:</p>
<pre style="width:509px;height:38px;"><span style="color:#2b91af;">Expect</span>.Call(context.GetService(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">IEmailSender</span>))).Return(emailSender).Repeat.Any();</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/97/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/97/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=97&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2007/06/23/monorail-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
		<item>
		<title>Code Generation</title>
		<link>http://benl.wordpress.com/2007/06/18/code-generation/</link>
		<comments>http://benl.wordpress.com/2007/06/18/code-generation/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 20:06:27 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2007/06/18/code-generation/</guid>
		<description><![CDATA[I was asked to produce some templates for generating (or alter some existing ones if I could find them) an ActiveRecord enabled domain model from an existing database schema. It got me thinking&#8230;&#160; I don&#8217;t agree with code generation in the domain model.
Why I hear you ask?
Unit Testing &#38; TDD
Generating the domain model in one [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=92&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was asked to produce some templates for generating (or alter some existing ones if I could find them) an ActiveRecord enabled domain model from an existing database schema. It got me thinking&#8230;&nbsp; I don&#8217;t agree with code generation <strong>in the domain model</strong>.</p>
<p>Why I hear you ask?</p>
<p><strong>Unit Testing &amp; TDD</strong></p>
<p>Generating the domain model in one fell swoop means you need to go back and retrofit your tests. This approach sucks for several reasons&#8230;</p>
<ul>
<li>Assumes you know enough about the domain to be making all your design decisions up front</li>
<li>The process of TDD ensures OO principles are adhered to (or at least easier to adhere to). Code generation assumes a certain amount of inflexibility in the produced code. You don&#8217;t get the chance to special case and <em>drive out</em> design by actually <em>consuming the code during design</em></li>
<li>It generally doesn&#8217;t get done. Show me a developer who <em>said </em>they would &#8220;add the tests later&#8221; and actually did</li>
</ul>
<p><strong>The learning process</strong></p>
<p>The code is being generated to make up for a lack of understanding of domain driven design and more importantly ActiveRecord/NHibernate by some team members. This is simply throwing more wood on the fire. I&#8217;ve said it before, nothing beats experiential learning. Give those developers the guidance and support they need to&nbsp;enable them to make design decisions and understand the technologies they&#8217;re using. <a href="http://www.ayende.com/Blog/archive/2007/06/17/Maintainable-but-for-whom.aspx" target="_blank">As Ayende said</a>:</p>
<blockquote><p>&#8230;if you need to <a href="http://codebetter.com/blogs/jean-paul_boodhoo/archive/2007/06/12/nothin-but-net-build-a-solid-core-wenatchee-wa-august-20th-24th.aspx">invest a week</a> in your developers, you will get your investment several times over when they produce better code, easier to maintain and extend and with fewer bugs</p>
</blockquote>
<p><strong>Backwards thought process</strong></p>
<p>I might not articulate this point particularly well, but still&nbsp;&nbsp;I sense&nbsp;there&#8217;s something not quite right about producing a domain model from a database. The object&nbsp;model should facilitate the relational model. Sure, not every system has the luxury of a green-field relational data source&#8230; But those that do are better served by a relational model that serves the domain model. Told you I wouldn&#8217;t articulate this very will didn&#8217;t I? <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>I&#8217;m not saying I don&#8217;t advocate code generation. It just needs to be applied liberally. Generation implicitly (and by its very definition) produces boiler-plate code. Boiler-plate code has no place in the domain model.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/92/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/92/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=92&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2007/06/18/code-generation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
		<item>
		<title>Infrastructure Ignorant/Anemic domain model?</title>
		<link>http://benl.wordpress.com/2007/06/11/infrastructure-ignorantanemic-domain-model/</link>
		<comments>http://benl.wordpress.com/2007/06/11/infrastructure-ignorantanemic-domain-model/#comments</comments>
		<pubDate>Mon, 11 Jun 2007 12:07:45 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2007/06/11/infrastructure-ignorantanemic-domain-model/</guid>
		<description><![CDATA[An example project I put together recently&#160;highlighting&#160;recommended baseline architecture has&#160;got me thinking about the best approach to domain driven design and incorporating the Domain Model.
The domain model dictates that your entities encapsulate business logic. In facilitating such a requirement your model classes stray from the traditional POCO principles and can end up incorporating infrastructure artifacts [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=88&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>An example project I put together recently&nbsp;highlighting&nbsp;recommended baseline architecture has&nbsp;got me thinking about the best approach to domain driven design and incorporating the <a href="http://www.martinfowler.com/eaaCatalog/domainModel.html" target="_blank">Domain Model</a>.</p>
<p>The domain model dictates that your entities encapsulate business logic. In facilitating such a requirement your model classes stray from the traditional POCO principles and can end up incorporating infrastructure artifacts such as persistence code and the like. The extreme end of this is being something like an ActiveRecord enabled model &#8211; whereby your ORM mappings are essentially C# properties adorned with attributes. This approach&nbsp;has a nasty whiff of&nbsp;<a href="http://c2.com/xp/CodeSmell.html" target="_blank">Code Smell</a> to me. Other evidence of this can include:</p>
<ul>
<li>Having to derive from special classes defined in your ORM framework
<li>Implementing special logic or types defined by your ORM framework
<li>Redefining object identity for ORM purposes
<li>Adding references to libraries required by your ORM framework</li>
</ul>
<p>A concrete example of this is when trying to serialize entities from an NHibernate and lazy-loading enabled domain model. Due to the cruft required by NHibernate when proxying lazy-loaded collections, certain un-serializable types are introduced. Of course, the way around this side effect is to create <a href="http://www.martinfowler.com/eaaCatalog/dataTransferObject.html" target="_blank">Data Transfer Objects</a> and move your data across the wire in this manner.</p>
<p>When layering in application design, the domain model naturally falls into the vertical. When enforcing strict layering the <a href="http://www.martinfowler.com/bliki/AnemicDomainModel.html" target="_blank">Anemic Domain Model</a> is the only (simple) approach worth considering. The anemic domain model describes a collection of entities exhibiting only data. They can exist outside of an ORM context and depend on fewer packages. Rather than perhaps exposing static methods on your model classes&nbsp;i.e:</p>
<pre><span style="color:rgb(43,145,175);">Publisher</span> publisher = <span style="color:rgb(43,145,175);">Publisher</span>.GetById(id);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The danger of this approach is that data access occurs wherever methods on the domain model are invoked. Also, does the domain model have much use if not enforcing the business rules in the domain? After all, the domain model is rarely, if ever a candidate for reuse. I certainly can&#8217;t think of any case where it would be.</p>
<p>The alternative is to&nbsp;move those responsibilities out into some form of repository, for example:</p>
<pre><span style="color:rgb(43,145,175);">Publisher</span> publisher = DefaultRepository&lt;<span style="color:rgb(43,145,175);">Publisher</span>&gt;.FindById(id);</pre>
<p>And in&nbsp;doing so you remove all your persistence concerns from the model. The entities then simply become dumb data holders and any persistence occurs only in the layers you allow it to.</p>
<p>I&#8217;m still not sure whether I prefer the former or the latter. DD purists will of course advocate the former, however my experience has been firmly around the latter approach. Can anyone help me decide?</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/88/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/88/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=88&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2007/06/11/infrastructure-ignorantanemic-domain-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
		<item>
		<title>RoR vs. Web Forms vs. MonoRail Pt2</title>
		<link>http://benl.wordpress.com/2007/06/01/ror-vs-web-forms-vs-monorail-pt2/</link>
		<comments>http://benl.wordpress.com/2007/06/01/ror-vs-web-forms-vs-monorail-pt2/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 12:01:55 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Monorail]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://benl.wordpress.com/2007/06/01/ror-vs-web-forms-vs-monorail-pt2/</guid>
		<description><![CDATA[Ok so in the last post I talked about some of the more obvious issues I have with ASP.NET and web forms development. Thankfully, the Castle Project&#8217;s MonoRail framework goes some way to alleviating that pain.
The Positives
MVC, MVP, ABC easy as 123&#8230;
Under the covers, MonoRail is a full MVC compliant framework essentially comprising a front [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=82&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ok so in the <a href="http://benl.wordpress.com/2007/05/31/ror-vs-web-forms-vs-monorail/">last post</a> I talked about some of the more obvious issues I have with ASP.NET and web forms development. Thankfully, the <a href="http://www.castleproject.org/monorail/index.html" target="_blank">Castle Project&#8217;s MonoRail</a> framework goes some way to alleviating that pain.</p>
<h3>The Positives</h3>
<p><strong>MVC, MVP, ABC easy as 123&#8230;</strong></p>
<p>Under the covers, MonoRail is a full MVC compliant framework essentially comprising a front controller sitting over the ASP.NET infrastructure intercepting specially formed URI&#8217;s. The HTML ends up in the browser  via your choice of view engine, with NVelocity (a fork of the Jakarta Velocity port) the default and most accessible, Brail being the Boo dynamic language and most performant option and of course a cruddy web forms engine too which nobody should use. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I&#8217;ve been comfortably using NVelocity for a while now, and provide testament that its not difficult to pick up.</p>
<p>The controller code orchestrates the flow of logic through the application and rails URI&#8217;s map nicely to actions on the controller which are ultimately public methods on the controller class itself. All nice and easy. Actions exposed on controllers derived from the magical <em>SmartDispatcherController</em> can translate posted form values into domain model objects for you by simply adding the <em>DataBind</em> attribute to your action&#8217;s argument list:</p>
<pre><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Save([<span style="color:#2b91af;">DataBind</span>(<span style="color:#a31515;">"publisher"</span>)] <span style="color:#2b91af;">Publisher</span> publisher)</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In the above example the publisher argument is passed into the <em>Save</em> action fully constructed via the form or query string values posted! This saves on the usual binding and scraping stuff you normally do in web forms and which almost always ends up sitting in the code behind untested. Note: the databinding stuff is of course very flexible and my example above just touches on the possibilities.</p>
<p><strong>ActiveRecord</strong></p>
<p>The model can be supplied with an <a href="http://www.castleproject.org/activerecord/index.html" target="_blank">ActiveRecord</a> enabled domain model. This of course abstracts away NHibernate behind the scenes. <strike>Unfortunately generic collections support doesn&#8217;t work right now but I believe that work is firmly underway</strike>.</p>
<p>Edit: Generic collections are supported, as long as you&#8217;re running from the trunk.</p>
<p>Domain entities are adorned with the necessary attributes defining how their properties are mapped to your data source. This is a departure from the usual hbm XML mapping files but just as expressive.</p>
<p>ActiveRecord also supplies simple validation in the form of special attributes including email validation, regular expression validation and the like.</p>
<p><strong>UI Components</strong></p>
<p>Reusability of UI components is achieved via <em>ViewComponent</em>. These can support nested sections, parameters etc.</p>
<p><strong>AJAX and client scripting support</strong></p>
<p>Built into MonoRail are a number of helpers which allow you to perform the usual AJAX stuff such as calling remote server side methods and callback support, Scriptaculous and Effects2 client side goodness. In fact the helper extensibility is a nice way of adding extensions and wrapping commonly performed functionality in the view.</p>
<p><strong>Convention over configuration</strong></p>
<p>Like RoR, MonoRail prefers convention over configuration. The project structure skeleton is the same throughout all MonoRail enabled solutions. The MonoRail installer also includes a handy templated solution provider for both VS.NET 2003 and 2005 to create the project skeleton and testing is included. Accustomed MonoRail developers can open any solution and just know where things are going to be.</p>
<p><strong>Testability</strong></p>
<p>One of the sore points of ASP.NET development was the unit testing difficulty. MonoRail overcomes this by enforcing the MVC pattern. Controllers are testable classes sitting outside of the usual ASP.NET cruft. There are a number of framework features within MonoRail which specifically aid testing.</p>
<p><strong>Scaffolding</strong></p>
<p>Like RoR, controllers adorned with the necessary scaffolding attributes can automatically produce the basic markup and logic for CRUD operations on your domain model. Handy for prototyping or creating rough-and-ready data entry capabilities in your applications.</p>
<p><strong>Container support</strong></p>
<p>MonoRail supports IoC via the <a href="http://www.castleproject.org/container/index.html" target="_blank">Windsor container</a>. Controllers and their dependencies/parameters can be injected by the container if necessary.</p>
<h3><strong>The negatives</strong></h3>
<p>MonoRail does have some negatives, which I will mull over:</p>
<p><strong>No 3rd party or ASP.NET web forms controls support</strong></p>
<p>I don&#8217;t really see this as an issue but can see that some ASP.NET developers will. Fans of the big UI library packages will complain, but there is this <em>old concept of HTML</em> and it is surprising how flexible it can be <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Most use of control libraries I have seen has been misguided, by this I mean they&#8217;re usually added to a screen just <em>because they can.</em></p>
<p>The web forms control library isn&#8217;t such an issue as things like calendars, grids and the like are not to difficult to duplicate the MonoRail way.</p>
<p><strong>Learning a whole bunch of new concepts/patterns/practices</strong></p>
<p>Most ASP.NET developers are what can only be described as morts. They&#8217;re not familiar with design patterns and good practices such as clean separation since they came from either ASP or VB (procedural backgrounds) so this stuff doesn&#8217;t come naturally. If you&#8217;ve used NHibernate you&#8217;ll pick up the ActiveRecord stuff in no time. Learning the template syntax for your chosen view engine is of course another consideration.</p>
<h3><font color="#000000">Summary</font></h3>
<p>In summary, the benefits of using MonoRail over web forms are clear. Clean separation of concerns, testability, reduced complexity and none of the web form cruft and artifacts. MonoRail won&#8217;t suit everybody, but even if you&#8217;re happy with web forms it&#8217;s definitely worth a look. Personally I think its the only way worth programming in the enterprise with ASP.NET today.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/82/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/82/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=82&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2007/06/01/ror-vs-web-forms-vs-monorail-pt2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
		<item>
		<title>AJAX Patterns</title>
		<link>http://benl.wordpress.com/2006/08/22/ajax-patterns/</link>
		<comments>http://benl.wordpress.com/2006/08/22/ajax-patterns/#comments</comments>
		<pubDate>Tue, 22 Aug 2006 12:26:58 +0000</pubDate>
		<dc:creator>benl</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">https://benl.wordpress.com/2006/08/22/ajax-patterns/</guid>
		<description><![CDATA[I&#8217;ve recently been fumbling around with AJAX and ASP.NET and came across this handy Ajax Patterns repository.
A few of the patterns which immediately stood out to me as the most useful and applicable in my scenario:
Cross-Domain Proxy
Can perform cross-site scripting access (traditionally disabled in most browsers) by mediating through the server.
Submission Throttling
Used to control the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=31&subd=benl&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve recently been fumbling around with AJAX and ASP.NET and came across this handy <a href="http://ajaxpatterns.org/Patterns" target="_blank">Ajax Patterns</a> repository.</p>
<p>A few of the patterns which immediately stood out to me as the most useful and applicable in my scenario:</p>
<p><b>Cross-Domain Proxy</b><br />
Can perform cross-site scripting access (traditionally disabled in most browsers) by mediating through the server.</p>
<p><b>Submission Throttling</b><br />
Used to control the amount of requests sent to the server. Rather than responding to every javascript event a local buffer is held and requests are processed at say a 200ms interval.</p>
<p><a href="http://ajaxpatterns.org/Patterns" target="_blank">Take a look&#8230;</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/benl.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/benl.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benl.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benl.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benl.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benl.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benl.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benl.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benl.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benl.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benl.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benl.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benl.wordpress.com&blog=178045&post=31&subd=benl&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://benl.wordpress.com/2006/08/22/ajax-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/146e52d49d361f85c0945487452fc6a0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ben</media:title>
		</media:content>
	</item>
	</channel>
</rss>