<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.mozingo.net/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Taller Code</title>
	
	<link>http://darrell.mozingo.net</link>
	<description>Darrell Mozingo's blog on .NET and development in general</description>
	<pubDate>Wed, 01 Jul 2009 23:04:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.mozingo.net/TallerCode" type="application/rss+xml" /><item>
		<title>2009 Goals - July Update</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/-WpFuK7c0Ok/</link>
		<comments>http://darrell.mozingo.net/2009/07/01/2009-goals-july-update/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 23:04:56 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Goals]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=288</guid>
		<description><![CDATA[We&#8217;re half way through 2009. How am I doing on my goals for the year? Let&#8217;s see (comments in italics after each goal):
Books

	Code Complete - Steve McConnell (yep, I&#8217;ve never actually read it)&#160;&#160;&#160; No progress.
	Patterns of Enterprise Application Architecture - Martin Fowler&#160;&#160;&#160; Ordered and on my bookshelf.
	Domain Driven Design - Erick Evans&#160;&#160;&#160; A bit over [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re half way through 2009. How am I doing on my <a href="http://darrell.mozingo.net/2009/01/02/new-year-new-goals-2009/">goals for the year</a>? Let&#8217;s see (comments in italics after each goal):</p>
<h3>Books</h3>
<ol>
	<li><a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670">Code Complete - Steve McConnell</a> (yep, I&#8217;ve never actually read it)&nbsp;&nbsp;&nbsp; <em>No progress.</em></li>
	<li><a href="http://www.amazon.com/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1229896370&amp;sr=8-1">Patterns of Enterprise Application Architecture - Martin Fowler</a>&nbsp;&nbsp;&nbsp; <em>Ordered and on my bookshelf.</em></li>
	<li><a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1229896453&amp;sr=1-1">Domain Driven Design - Erick Evans</a>&nbsp;&nbsp;&nbsp; <em>A bit over 100 pages left.</em></li>
	<li><a href="http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1229896657&amp;sr=1-1">Working Effectively With Legacy Code - Robert Martin</a>&nbsp;&nbsp;&nbsp; <em>No progress.</em></li>
</ol>
<h3>Tools/Techniques/Processes @ Work</h3>
<ul>
    <li><strike>NHibernate and all its trimmings (FluentNHibernate, LINQ to NHibernate, etc), which I&#8217;ll need on a project here real soon.</strike>&nbsp; <em>Done, but still picking up stuff.</em></li>
    <li>Actually move from CC.NET to Team City (last attempt didn&#8217;t go so well).&nbsp; <em>No progress.</em></li>
    <li>Build a more robust build script and management process - including production deployment scenarios.&nbsp;&nbsp; <em>No progress.</em></li>
    <li>Messaging framework, either <a href="http://code.google.com/p/masstransit/">MassTransit</a>, <a href="http://www.nservicebus.com/">NServiceBus</a>, or Ayende&#8217;s new <a href="http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx">Rhino Service Bus</a> if he&#8217;s able to release it in time for our current project.&nbsp; <em>No progress as we haven&#8217;t needed any yet.</em></li>
</ul>
<h3>Involvement</h3>
<ul>
    <li>We have weekly meetings to catch everyone up on what we&#8217;re doing, but I want to present on an actual topic during at least 2 of these - and present in a way where the other development teams will see the use in picking up the presented tool/technique.&nbsp;&nbsp;&nbsp; <em>Our meetings are still halted, but I&#8217;m hoping to do an intro IoC/DI presentation if they ever start again.</em></li>
    <li>Have at least one meeting of the <a href="http://www.cantonalt.net">CantonALT.NET</a> group and see if it can ever get up on its feet.&nbsp;&nbsp; <em>No progress, but we have had a few Code &#038; Coffee get togethers.</em></li>
    <li>The two blog posts per month target John put out there seems doable, so I&#8217;ll borrow it :)&nbsp;&nbsp;&nbsp; <em>Pretty much on target.</em></li>
    <li>At least 3 feature/patch submissions to open source projects.&nbsp; <em>No further progress past the last update.</em></li>
</ul>
<h3>Productivity</h3>
<ul>
    <li>Trim RSS feed size by 1/3 (presently at 127, so trim it to at least 85) and cut time viewing it by half. I&#8217;ve gotten much better this past year at cutting through the useless stuff, but there&#8217;s still a lot there and it sucks up too much of my time.&nbsp; <em>Down to 103. Not too bad.</em></li>
</ul>
<p>Once again, the reading is killing me. It&#8217;s not that it&#8217;s not interesting, it&#8217;s just time. Between a few magazines I read (some technical, some not) and projects around the house, reading time always seems to take a back seat. I&#8217;ll get into it for a bit and fly through the pages, but that &#8220;bit&#8221; is usually only a day or two, unfortunately. Lets see how the next two months go.</p>
<p>I&#8217;ll update again in the begining of September.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/07/01/2009-goals-july-update/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/07/01/2009-goals-july-update/</feedburner:origLink></item>
		<item>
		<title>Strongly Typed Views With Mvc Contrib - Part 3</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/pkxEdOAPTC4/</link>
		<comments>http://darrell.mozingo.net/2009/06/20/strongly-typed-views-with-mvc-contrib-part-3/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 16:20:04 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=166</guid>
		<description><![CDATA[Part 1 discussed the benefits of a strongly typed view and part 2 went through the typical usage of the Mvc Contrib project&#8217;s fluent HTML library. Now we&#8217;ll take a look at a neater usage for it - validation.

Each extension in the Mvc Contrib fluent HTML library takes &#8220;behaviors&#8221; into account, applying all known behaviors [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://darrell.mozingo.net/2009/04/30/strongly-typed-views-with-mvc-contrib-part-1/">Part 1</a> discussed the benefits of a strongly typed view and <a href="http://darrell.mozingo.net/2009/05/23/strongly-typed-views-with-mvc-contrib-part-2/">part 2</a> went through the typical usage of the Mvc Contrib project&#8217;s fluent HTML library. Now we&#8217;ll take a look at a neater usage for it - validation.</p>

<p>Each extension in the Mvc Contrib fluent HTML library takes &#8220;behaviors&#8221; into account, applying all known behaviors first when rendering themselves to strings. These behaviors are defined by the following interface:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IMemberBehavior <span style="color: #008000;">:</span> IBehaviorMarker
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">void</span> Execute<span style="color: #000000;">&#40;</span>IMemberElement element<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>Very simple. The interface defines a single method that takes in an <code>IMemberElement</code>, which provides the LINQ expression being used to render the control and also inherits from the <code>IElement</code> interface, which is the base interface all the HTML extensions end up deriving from:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IElement
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// TagBuilder object used to generate HTML.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	TagBuilder Builder <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// How the tag should be closed.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	TagRenderMode TagRenderMode <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Set the value of the specified attribute.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;name&quot;&gt;The name of the attribute.&lt;/param&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;value&quot;&gt;The value of the attribute.&lt;/param&gt;</span>
	<span style="color: #0600FF;">void</span> SetAttr<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> name, <span style="color: #FF0000;">object</span> value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Set the value of the specified attribute.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;name&quot;&gt;The name of the attribute.&lt;/param&gt;</span>
	<span style="color: #FF0000;">string</span> GetAttr<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> name<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// Remove an attribute.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;name&quot;&gt;The name of the attribute to remove.&lt;/param&gt;</span>
	<span style="color: #0600FF;">void</span> RemoveAttr<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> name<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// The text for the label rendered before the element.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #FF0000;">string</span> LabelBeforeText <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// The text for the label rendered after the element.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #FF0000;">string</span> LabelAfterText <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
	<span style="color: #008080; font-style: italic;">/// The class for labels rendered before or after the element.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
	<span style="color: #FF0000;">string</span> LabelClass <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>This allows a behavior to do basic modifications to an element, including changing HTML attributes and adding text before/after the element. More advanced operations can be done by breaking polymorphism and checking what type the <code>IElement</code> parameter actually is. Mvc Contrib bundles in one behavior by default, the <code>ValidationBehavior</code>, which checks ASP.NET MVC&#8217;s ModelState for any possible errors to display, effectively making the Mvc Contrib&#8217;s HTML helpers act the same as the built in ASP.NET MVC&#8217;s when it comes to error handling.</p>

<p>You&#8217;ll notice above I said each HTML extension takes all &#8220;known&#8221; behaviors into account when rendering themselves to strings. So how do the extensions learn about these behaviors? Simply put, the <code>ModelViewPage</code> we had our view page inherit from takes an array of them in one of its constructor overloads. The default constructor only loads the ValidationBehavior. All we need to do is create our own view base page, inherit from the ModelViewPage, and pass in our own behaviors like so:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FluentViewPage<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> <span style="color: #008000;">:</span> ModelViewPage<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> where T <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> FluentViewPage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> MaxLengthBehavior<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>There&#8217;s really not much to the above behavior, either. Simply have it inherit from <code>IMemberBehavior</code> and you&#8217;re good to go. Here it is in all its entirety:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MaxLengthBehavior <span style="color: #008000;">:</span> IMemberBehavior
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Execute<span style="color: #000000;">&#40;</span>IMemberElement element<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var attribute <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemberBehaviorHelper<span style="color: #008000;">&lt;</span>StringLengthAttribute<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetAttribute</span><span style="color: #000000;">&#40;</span>element<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>attribute <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> element <span style="color: #008000;">is</span> ISupportsMaxLength<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			element.<span style="color: #0000FF;">SetAttr</span><span style="color: #000000;">&#40;</span>HtmlAttribute.<span style="color: #0000FF;">MaxLength</span>, attribute.<span style="color: #0000FF;">MaximumLength</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>The passed in member element knows the property specified in the <code>this.TextBox(x => x.Name)</code> call (Name, in this case), as well as all the elements defined on the IElement interface above. We take that and use a helper class to pull the desired attribute off the passed in property. If it has the attribute we&#8217;re looking for, and supports setting a maximum length (checking using the <code>ISupportsMaxLength</code> marker interface so we&#8217;re not trying to somehow set the max length on a checkbox, for example), we set the max length HTML attribute on the element. Pretty simple, but again, this is only really scratching the surface of what can be done with these behaviors.</p>

<p>So with all this in place, simply slap the <code>StringLenght</code> attribute on any needed view model properties. For instance, if we modify the CustomerViewModel&#8217;s name property like this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>StringLength<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">30</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Name <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>The outputted HTML would be:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;input id=&quot;Name&quot; maxlength=&quot;30&quot; name=&quot;Name&quot; type=&quot;text&quot; value=&quot;John&quot; /&gt;</pre></td></tr></table></div>




<p>Neat, huh? In our current project, we&#8217;re using these to automatically denote required fields, and in conjunction with <a href="http://www.codeplex.com/xval">xVal</a>, require those fields complete with client side checks. All from a few simple attributes.</p>

<p>A zip of the final project can be found <a href="http://darrell.mozingo.net/wp-content/uploads/2009/06/MvcContribFluentHtml.zip">here</a>, for reference.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/06/20/strongly-typed-views-with-mvc-contrib-part-3/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/06/20/strongly-typed-views-with-mvc-contrib-part-3/</feedburner:origLink></item>
		<item>
		<title>TortoiseSVN 1.6+ Hot Keys</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/YQtzgd8CCQE/</link>
		<comments>http://darrell.mozingo.net/2009/06/17/tortoisesvn-16-hot-keys/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 11:50:00 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Quickie]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=264</guid>
		<description><![CDATA[The latest releases of Tortoise SVN (above 1.6) have taken away the ALT+O hot keys that used to be on every dialog (though it sounds like they&#8217;ve added them back in to the trunk). This caused quite an uproar by many keyboarders, myself included.

Until the trunk is stable and the ALT+O keys are reintroduced, though, [...]]]></description>
			<content:encoded><![CDATA[<p>The latest releases of <a href="http://tortoisesvn.tigris.org/">Tortoise SVN</a> (above 1.6) have taken away the ALT+O hot keys that used to be on every dialog (though it <a href="http://www.nabble.com/Re:-Bug--Alt%2BO-on-commit-dialog-no-longer-OKs-it-p23553686.html">sounds like they&#8217;ve added them back in to the trunk</a>). This caused quite an uproar by many keyboarders, myself included.</p>

<p>Until the trunk is stable and the ALT+O keys are reintroduced, though, know that CTRL+ENTER will substitute on pretty much all the dialogs (or ESC for Cancel). These are the &#8220;standard&#8221; Windows OK &#038; Cancel shortcuts, and apparently the custom accelerator keys are hold overs from legacy WinAPI code.</p>

<p>I&#8217;ve grown accustomed to CTRL+ENTER at this point, but I&#8217;ll be happy to hopefully have my old friend, ALT+O, back soon.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/06/17/tortoisesvn-16-hot-keys/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/06/17/tortoisesvn-16-hot-keys/</feedburner:origLink></item>
		<item>
		<title>Code &amp; Coffee - Getting Started</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/iWvLlC_L65c/</link>
		<comments>http://darrell.mozingo.net/2009/06/10/code-coffee-getting-started/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 22:00:25 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=246</guid>
		<description><![CDATA[We had a couple of new guys join us for last week&#8217;s Code &#038; Coffee, and during the 15 minutes or so we spent helping get them up to speed I realized a quick &#8220;getting started&#8221; post might be in order to help future attendees. 

For starters, download the Ruby 1.8.6 one-click installer (from the [...]]]></description>
			<content:encoded><![CDATA[<p>We had a couple of new guys join us for last week&#8217;s <a href="http://darrell.mozingo.net/2009/05/08/code-and-coffee/">Code &#038; Coffee</a>, and during the 15 minutes or so we spent helping get them up to speed I realized a quick &#8220;getting started&#8221; post might be in order to help future attendees. </p>

<p>For starters, download the <a href="http://rubyforge.org/frs/download.php/47082/ruby186-27_rc2.exe">Ruby 1.8.6 one-click installer</a> (from the <a href="http://www.ruby-lang.org/en/downloads/">main Ruby site</a>). It may or may not require a reboot to get the standard C:\ruby install directory into your PATH variable. Open a command prompt and type <code>ruby --version</code> to make sure it&#8217;s working correctly.</p>

<p>We&#8217;re working our way through <a href="http://github.com/edgecase/ruby_koans/tree/master">Edge Case&#8217;s Ruby Koans</a> right now, which are basically a whole suite of failing unit tests that teach you more about the language as you get them passing. There&#8217;s a download link in the middle of the upper portion of their GitHub page. Once you download and extract it somewhere, open up a command prompt in the root directory and run the <code>rake</code> command. It will use the <strong>Rakefile</strong> in that directory by default and it should tell you the first test failed. Open the respective file in the koans directory, try getting it to pass, and re-run rake. Keep going through that process, test by test. Some are blatantly obvious, while others require some research. It&#8217;s best if you think about what you&#8217;re actually doing too, besides just trying to make the test pass. We&#8217;re currently somewhere in the <strong>about_hashes.rb</strong> file.</p>

<p>The idea is to get through these, soaking up as much as we can, then probably jump into an intro <a href="http://rubyonrails.org/">Rails</a> application, eventually working on some sort of blog for the Code &#038; Coffee. Should be fun. I&#8217;d also like to get into either <a href="http://rspec.info/">RSpec</a> or <a href="http://cukes.info/">Cucumber</a> along the way, and see what TDD/BDD in Ruby is like as I&#8217;ve always heard how great it is.</p>

<p>Our next get together will be Friday, June 19th @ 7am. Hope to see you there, and let me know if you have any problems with getting this stuff setup.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/06/10/code-coffee-getting-started/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/06/10/code-coffee-getting-started/</feedburner:origLink></item>
		<item>
		<title>Code and Coffee - Inital Impressions</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/bgvBznEQwyY/</link>
		<comments>http://darrell.mozingo.net/2009/05/24/code-and-coffee-inital-impressions/#comments</comments>
		<pubDate>Sun, 24 May 2009 10:36:39 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=226</guid>
		<description><![CDATA[We&#8217;ve had two meet-ups for the Code and Coffee already now, and it seems to be going pretty good. We decided to tackle a simple Rails application, as none of us had used Ruby or Rails before much, and thought it&#8217;d be worth taking a look at it.

We&#8217;re working through EdgeCase&#8217;s Ruby Koans to familurize [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve had two meet-ups for the <a href="http://darrell.mozingo.net/2009/05/08/code-and-coffee/">Code and Coffee</a> already now, and it seems to be going pretty good. We decided to tackle a simple Rails application, as none of us had used Ruby or Rails before much, and thought it&#8217;d be worth taking a look at it.</p>

<p>We&#8217;re working through EdgeCase&#8217;s <a href="http://github.com/edgecase/ruby_koans/tree/master">Ruby Koans</a> to familurize ourselves with Ruby first, then we&#8217;ll start tackling some Rails examples. The Koans are a great way to introduce people to the language. Really, they&#8217;re brilliant. The meet-ups have stuck to about an hour in length so far, and we&#8217;ve determined we&#8217;ll meet every other Friday, still as 7am at the Canton Arabica that was previously mentioned. <b>That puts our next get together on June 5th</b>.</p>

<p>It was only <a href="http://www.malachicomputer.com/blog/default.aspx">Jason Lautzenheiser</b>, <a href="http://www.saberware.com">Eric Schliffka</a>, and myself there, but we&#8217;re hopeful more people will start coming. There&#8217;s been quite a bit of interest, so we&#8217;ll see. Looks like these meetings will be pretty helpful, though, keeping all of us on tasks, meeting some new people, and most important, pushing our comfort zone in development terms. They&#8217;re pretty fun, to boot! Hope to see you at the next one!</p>
]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/05/24/code-and-coffee-inital-impressions/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/05/24/code-and-coffee-inital-impressions/</feedburner:origLink></item>
		<item>
		<title>Strongly Typed Views With Mvc Contrib - Part 2</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/L0jIN2fYvCk/</link>
		<comments>http://darrell.mozingo.net/2009/05/23/strongly-typed-views-with-mvc-contrib-part-2/#comments</comments>
		<pubDate>Sat, 23 May 2009 09:36:44 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=164</guid>
		<description><![CDATA[In part 1, I explained the reasoning behind using strongly typed HTML helpers in your view (with ease of refactoring being chief among them). Now that you have an ASP.NET MVC project referencing the needed Mvc Contrib assemblies, how can you actually get started using them?

Lets start by taking this sexy looking view model that [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://darrell.mozingo.net/2009/04/30/strongly-typed-views-with-mvc-contrib-part-1/">part 1</a>, I explained the reasoning behind using strongly typed HTML helpers in your view (with ease of refactoring being chief among them). Now that you have an ASP.NET MVC project referencing the needed Mvc Contrib assemblies, how can you actually get started using them?</p>

<p>Lets start by taking this sexy looking view model that represents a single customer:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomerViewModel
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Id <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Name <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">public</span> CustomerType Type <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>Where <code>CustomerType</code> is a standard enumeration:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> CustomerType
<span style="color: #000000;">&#123;</span>
	Preferred,
	Standard,
	Delinquent
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>Then we&#8217;ll provide an easy enough action for editing a customer:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// In reality, we'd take in a customer Id and use that to load the customer from the database.</span>
<span style="color: #0600FF;">public</span> ActionResult Edit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	var customerViewModelLoadedFromDatabase <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerViewModel
	                                          	<span style="color: #000000;">&#123;</span>
	                                          		Id <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>,
	                                          		Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;John&quot;</span>,
                                                    		Type <span style="color: #008000;">=</span> CustomerType.<span style="color: #0000FF;">Standard</span>
	                                          	<span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Edit&quot;</span>, customerViewModelLoadedFromDatabase<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>Before looking at the view, though, we&#8217;ll need to reference the <code>MvcContrib.FluentHtml.dll</code> assembly, and add the following to our <code>web.config</code>, under the configuration/system.web/pages/namespaces node:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;MvcContrib.FluentHtml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>




<p>With all that out of the way, here&#8217;s the relevant portion of the edit view:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span> <span style="color: #0600FF;">using</span><span style="color: #000000;">&#40;</span>Html.<span style="color: #0000FF;">BeginForm</span><span style="color: #008000;">&lt;</span>CustomerController<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">%&gt;</span>
	<span style="color: #008000;">&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Hidden</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Id</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
	<span style="color: #008000;">&lt;</span>table<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;</span>b<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Label</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;:&lt;/</span>b<span style="color: #008000;">&lt;/</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;</span>b<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Label</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Type</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Customer Type&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;:&lt;/</span>b<span style="color: #008000;">&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Select</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Type</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Options</span><span style="color: #008000;">&lt;</span>CustomerType<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Selected</span><span style="color: #000000;">&#40;</span>Model.<span style="color: #0000FF;">Type</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>td colspan<span style="color: #008000;">=</span><span style="color: #666666;">&quot;2&quot;</span> align<span style="color: #008000;">=</span><span style="color: #666666;">&quot;center&quot;</span><span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">SubmitButton</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Update Customer&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span>
			<span style="color: #008000;">&lt;/</span>td<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>table<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;%</span> <span style="color: #000000;">&#125;</span> <span style="color: #008000;">%&gt;</span></pre></td></tr></table></div>




<p>First, note that <b>the page must inherit from <code>MvcContrib.FluentHtml.ModelViewPage<T></code>, not the standard Mvc <code>ViewPage</code> class</b>. The strongly typed Html.BeginForm is from the <a href="http://www.asp.net/mvc/download/">Mvc Futures Assembly</a>. Also, these extensions are on the ModelViewPage base class, not the normal Html helper type methods (i.e. they&#8217;re <code>this.TextBox</code> instead of <code>Html.TextBox</code>).</p>

<p>These fields are mostly self explanatory: you&#8217;ll see the Id is written to a hidden field on the page using the <code>Hidden</code> extension, the Name using the <code>TextBox</code> extension, and the Type (as a drop down list) using the <code>Select</code> extension. All of these extensions have quite a few customizable methods on them, such as the Options and Selected methods on the Select extension shown above. The options method allows you to specify (via generic type or otherwise with an overload) the options for the drop down, while the selected method allows you to specify which option of the list should be highlighted (it&#8217;ll default to the top item if the parameter is null). The Label extension can generate an HTML label &#8220;for&#8221; the specified control, so by clicking the &#8220;Name&#8221; or &#8220;Customer Type&#8221; labels above, most browsers will set focus to their respective controls.</p>

<p>Another quite useful extension is the <code>this.IdFor(x => x.Name)</code>, which for our setup would simply output <b>Name</b>, but it comes in handy when dealing with sub objections and collections. This allows you to put a strongly typed reference to your control id&#8217;s in Javascript, so renaming the view model&#8217;s property renames <i>all</i> references, including the Javascript ones. Huge help there.</p>

<p>Alright, I&#8217;ll admit for basic cases like this it&#8217;s a bit harder to see the immediate benefits of strong typing, so let&#8217;s complicate it a tad by introducing a sub view model for an address, and a collection of order view models by adding this in the Edit action to the customer object initialization:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">Address <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AddressViewModel
          	<span style="color: #000000;">&#123;</span>
          		Street <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;123 Easy St.&quot;</span>,
          		City <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Beverly Hills&quot;</span>,
          		State <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;CA&quot;</span>,
          		Zip <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;90210&quot;</span>
          	<span style="color: #000000;">&#125;</span>,
Orders <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>OrderViewModel<span style="color: #008000;">&gt;</span>
         	<span style="color: #000000;">&#123;</span>
         		<span style="color: #008000;">new</span> OrderViewModel
         			<span style="color: #000000;">&#123;</span>
					Id <span style="color: #008000;">=</span> <span style="color: #FF0000;">300</span>,
         				ApplyDiscount <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>,
         				Quantity <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span>
         			<span style="color: #000000;">&#125;</span>,
         		<span style="color: #008000;">new</span> OrderViewModel
         			<span style="color: #000000;">&#123;</span>
					Id <span style="color: #008000;">=</span> <span style="color: #FF0000;">301</span>,
         				ApplyDiscount <span style="color: #008000;">=</span> <span style="color: #0600FF;">false</span>,
         				Quantity <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span>
         			<span style="color: #000000;">&#125;</span>
         	<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>




<p>Here&#8217;s one way to modify the edit page to deal with these new objects:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;</span>b<span style="color: #008000;">&gt;</span>Address<span style="color: #008000;">:&lt;/</span>b<span style="color: #008000;">&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;</span>table<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>Street<span style="color: #008000;">:&lt;/</span>td<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Address</span>.<span style="color: #0000FF;">Street</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>City<span style="color: #008000;">:&lt;/</span>td<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Address</span>.<span style="color: #0000FF;">City</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>State<span style="color: #008000;">:&lt;/</span>td<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Address</span>.<span style="color: #0000FF;">State</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Styles</span><span style="color: #000000;">&#40;</span>width <span style="color: #008000;">=&gt;</span> <span style="color: #666666;">&quot;30px&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>Zip<span style="color: #008000;">:&lt;/</span>td<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Address</span>.<span style="color: #0000FF;">Zip</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;/</span>table<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>td<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;</span>b<span style="color: #008000;">&gt;</span>Orders<span style="color: #008000;">:&lt;/</span>b<span style="color: #008000;">&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;%</span> <span style="color: #0600FF;">for</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> Model.<span style="color: #0000FF;">Orders</span>.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">%&gt;</span>
		<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Hidden</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Orders</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Id</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span>
			<span style="color: #008000;">&lt;</span>table<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
					<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;</span>Quantity<span style="color: #008000;">:&lt;/</span>td<span style="color: #008000;">&gt;</span>
					<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Orders</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Quantity</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;</span>tr<span style="color: #008000;">&gt;</span>
					<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Label</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Orders</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ApplyDiscount</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Apply Discount&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;:&lt;/</span>td<span style="color: #008000;">&gt;</span>
					<span style="color: #008000;">&lt;</span>td<span style="color: #008000;">&gt;&lt;%=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CheckBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Orders</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ApplyDiscount</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">%&gt;&lt;/</span>td<span style="color: #008000;">&gt;</span>
				<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span>
			<span style="color: #008000;">&lt;/</span>table<span style="color: #008000;">&gt;</span>
		<span style="color: #008000;">&lt;/</span>td<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;%</span> <span style="color: #000000;">&#125;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;/</span>tr<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>




<p>You&#8217;ll notice this is all still in a strongly typed manor, even with the sub object and object collection. These are basically the same extensions as before, except for <code>CheckBox</code>, which works as you&#8217;d expect. Note the Styles method on most of these extensions, which takes a param of Func&#8217;s that allows you to define CSS styles. The state text box, for examples, is defining the width CSS style and setting it to 30px.</p>

<p>All of these extensions take the current ViewData into account when rendering, just as the default ASP.NET MVC extensions do. For instance, the above CheckBox extension will render &#8220;checked&#8221; if the ApplyDiscount property is true coming in. You can also start to imagine how using the <code>this.IdFor(x => x.property)</code> extension to reference controls in your Javascript would start to come in handy here, as HTML id tag rendering for arrays (where the brackets are replaced with underscores) and sub objects (where dots are replaced with underscores) can get pretty complex.</p>

<p>That pretty much covers the basics of the FluentHTML extensions. These reasons alone were enough to get my team to switch our current project over to using them, let alone some of the more advanced features, such as basic validation integration. I&#8217;ll go over a few of those in the next part of this series, though. You can grab a zip of the current project <a href="http://darrell.mozingo.net/wp-content/uploads/2009/05/MvcContribFluentHtml.zip">here</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/05/23/strongly-typed-views-with-mvc-contrib-part-2/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/05/23/strongly-typed-views-with-mvc-contrib-part-2/</feedburner:origLink></item>
		<item>
		<title>Code and Coffee</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/lX_yTmn9FIc/</link>
		<comments>http://darrell.mozingo.net/2009/05/08/code-and-coffee/#comments</comments>
		<pubDate>Fri, 08 May 2009 17:04:42 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=187</guid>
		<description><![CDATA[A week or two ago Jason Lautzenheiser emailed around about to a few of us about starting a local Code and Coffee here in the Canton area, and I think it&#8217;s a great idea. We haven&#8217;t set a schedule or anything, but the first get together will be Friday, May 15th @ 7 AM at Canton Arabica, [...]]]></description>
			<content:encoded><![CDATA[<img src="http://darrell.mozingo.net/wp-content/uploads/2009/05/coffeeandcode.jpg" alt="Coffee and Code" title="Coffee and Code" class="alignnone size-full wp-image-194" style="float: right; padding-left: 10px;" /><p>A week or two ago <a href="http://www.malachicomputer.com/blog/">Jason Lautzenheiser</a> emailed around about to a few of us about starting a local <a href="http://www.codeandcoffee.info/">Code and Coffee</a> here in the Canton area, and I think it&#8217;s a great idea. We haven&#8217;t set a schedule or anything, but the first get together will be Friday, May 15th @ 7 AM at <a href="http://cantonarabica.com/">Canton Arabica</a>, right on Dressler in Belden. Everyone&#8217;s already busy in the evenings, so we figure we&#8217;ll give this whole &#8220;first thing in the morning&#8221; time slot a shot.</p>

<p>Basically we&#8217;ll get together to do some pairing on whatever interests everyone, with an eye towards pushing comfort zones (read: new languages and technologies). Very informal. Stop by if you can make it. If we can&#8217;t figure out what we&#8217;ll do before next Friday, we&#8217;ll just call this first one a meet and greet and pick a topic for next time. Since the idea is to pair, don&#8217;t worry if you don&#8217;t have a laptop.</p>

<p>Don&#8217;t fret about the early AM thing. I&#8217;m not a morning person myself either (my alarm isn&#8217;t even set until 7:20 normally), but it should be good to get the ol&#8217; brain neurons firing that early in the morning.</p>

<p>If you&#8217;re interested, let either Jason or myself know. We&#8217;re planning on keeping it to about an hour in length.</p>

<p>Hope to see you there!</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/05/08/code-and-coffee/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/05/08/code-and-coffee/</feedburner:origLink></item>
		<item>
		<title>2009 Goals - May Update</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/tE0sItpJ0fQ/</link>
		<comments>http://darrell.mozingo.net/2009/05/01/2009-goals-may-update/#comments</comments>
		<pubDate>Fri, 01 May 2009 09:18:07 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Goals]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=170</guid>
		<description><![CDATA[We&#8217;re 1/3rd of the way through 2009. How am I doing on my goals for the year? Let&#8217;s see (comments in italics after each goal):
Books

	Code Complete - Steve McConnell (yep, I&#8217;ve never actually read it)&#160;&#160;&#160; No progress.
	Patterns of Enterprise Application Architecture - Martin Fowler&#160;&#160;&#160; Ordered and on my bookshelf.
	Domain Driven Design - Erick Evans&#160;&#160;&#160; About [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re 1/3rd of the way through 2009. How am I doing on my <a href="http://darrell.mozingo.net/2009/01/02/new-year-new-goals-2009/">goals for the year</a>? Let&#8217;s see (comments in italics after each goal):</p>
<h3>Books</h3>
<ol>
	<li><a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670">Code Complete - Steve McConnell</a> (yep, I&#8217;ve never actually read it)&nbsp;&nbsp;&nbsp; <em>No progress.</em></li>
	<li><a href="http://www.amazon.com/Enterprise-Application-Architecture-Addison-Wesley-Signature/dp/0321127420/ref=pd_bbs_sr_1?ie=UTF8&amp;s=books&amp;qid=1229896370&amp;sr=8-1">Patterns of Enterprise Application Architecture - Martin Fowler</a>&nbsp;&nbsp;&nbsp; <em>Ordered and on my bookshelf.</em></li>
	<li><a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1229896453&amp;sr=1-1">Domain Driven Design - Erick Evans</a>&nbsp;&nbsp;&nbsp; <em>About half way through - good stuff!</em></li>
	<li><a href="http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1229896657&amp;sr=1-1">Working Effectively With Legacy Code - Robert Martin</a>&nbsp;&nbsp;&nbsp; <em>No progress.</em></li>
</ol>
<h3>Tools/Techniques/Processes @ Work</h3>
<ul>
    <li><strike>NHibernate and all its trimmings (FluentNHibernate, LINQ to NHibernate, etc), which I&#8217;ll need on a project here real soon.</strike>&nbsp; <em>Done (though with NHibernate, learning is always ongoing!)</em></li>
    <li>Actually move from CC.NET to Team City (last attempt didn&#8217;t go so well).&nbsp; <em>No progress.</em></li>
    <li>Build a more robust build script and management process - including production deployment scenarios.&nbsp;&nbsp; <em>Worked on the script and have a very basic one up and running. The build portion needs a lot more refinement before I get anything more advanced in there though.</em></li>
    <li>Messaging framework, either <a href="http://code.google.com/p/masstransit/">MassTransit</a>, <a href="http://www.nservicebus.com/">NServiceBus</a>, or Ayende&#8217;s new <a href="http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx">Rhino Service Bus</a> if he&#8217;s able to release it in time for our current project.&nbsp; <em>No progress as we haven&#8217;t needed any yet.</em></li>
</ul>
<h3>Involvement</h3>
<ul>
    <li>We have weekly meetings to catch everyone up on what we&#8217;re doing, but I want to present on an actual topic during at least 2 of these - and present in a way where the other development teams will see the use in picking up the presented tool/technique.&nbsp;&nbsp;&nbsp; <em>Our meetings were/are halted for a bit, but I think an intro IoC/DI presentation when they pick back up in a bit is in order.</em></li>
    <li>Have at least one meeting of the <a href="http://www.cantonalt.net">CantonALT.NET</a> group and see if it can ever get up on its feet.&nbsp;&nbsp; <em>No progress.</em></li>
    <li>The two blog posts per month target John put out there seems doable, so I&#8217;ll borrow it :)&nbsp;&nbsp;&nbsp; <em>Sorta keeping on target - I didn&#8217;t really have two substantial ones in March, but I made up for it (just in time yesterday!) by doing 3 in April.</em></li>
    <li>At least 3 feature/patch submissions to open source projects.&nbsp; <em>Submitted quite a few patches (some small, some a bit meatier) to the <a href="http://mvccontrib.codeplex.com/SourceControl/PatchList.aspx">MVC Contrib</a> project and one (yet unaplied) one to the <a href="http://www.codeplex.com/xval">xVal</a> project. So while I guess this goal is technically met, I&#8217;d still like to do something of a little more substance to push myself.</em></li>
</ul>
<h3>Productivity</h3>
<ul>
    <li>Trim RSS feed size by 1/3 (presently at 127, so trim it to at least 85) and cut time viewing it by half. I&#8217;ve gotten much better this past year at cutting through the useless stuff, but there&#8217;s still a lot there and it sucks up too much of my time.&nbsp; <em>Down a bit to 116. Hey, it&#8217;s a start!</em></li>
</ul>
<p>Starting on the reading was good, but only half a book in two months is pretty sad. Everything else is more or less on schedule, but I need to start thinking about that CantonALT.NET meeting (or something similar).</p>
<p>I&#8217;ll update again in the begining of July.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/05/01/2009-goals-may-update/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/05/01/2009-goals-may-update/</feedburner:origLink></item>
		<item>
		<title>Strongly Typed Views With Mvc Contrib - Part 1</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/ungrBiiXBO0/</link>
		<comments>http://darrell.mozingo.net/2009/04/30/strongly-typed-views-with-mvc-contrib-part-1/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 23:18:46 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=152</guid>
		<description><![CDATA[Out of the box, ASP.NET MVC uses weakly typed extension methods to generate various HTML elements (inputs, check boxes, select lists, etc). By weakly typed I mean they require strings, which are actually strings based on the properties of your view model. For instance, given this view model:


1
2
3
4
5
public class OrderViewModel
&#123;
	public int Quantity &#123; get; set; [...]]]></description>
			<content:encoded><![CDATA[<p>Out of the box, ASP.NET MVC uses weakly typed extension methods to generate various HTML elements (inputs, check boxes, select lists, etc). By weakly typed I mean they require strings, which are actually strings based on the properties of your view model. For instance, given this view model:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> OrderViewModel
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Quantity <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> ApplyDiscount <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>



<p>You&#8217;d generate an input box for the quantity, using the standard HTML helper extensions, like so:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> Html.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Quantity&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre></td></tr></table></div>



<p>Ew, strings. That&#8217;s so .NET 1.1, right? With .NET 3 we get Expressions and lambdas. Now lambdas are just more concise ways to define delegates (methods you can pass around as variables), so they&#8217;re nothing really new new. Expressions, for the purposes of this post, allow you to specify, in a compile safe manner, which property you want to use for something, which can then be parsed during run-time to get the property&#8217;s string name (suffice to say Expressions can do much more and form the foundation for LINQ To SQL). For instance, what if, instead of using the above TextBox method for the quantity product, we could do this:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%=</span> Html.<span style="color: #0000FF;">TextBox</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Quantity</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">%&gt;</span></pre></td></tr></table></div>



<p>Rest assured it&#8217;d produce the same HTML in the end while giving us the type safety we&#8217;re looking for. What do I mean by type safety? I mean you can preform a rename refactoring on Quantity and you&#8217;d also rename the usage in the view (Resharper will actually do most rename refactorings on strings too, but it&#8217;s not 100% reliable - it&#8217;s a guess at best). That means less chance of something breaking (especially something you won&#8217;t find out about until runtime when your customers are in there), which means high quality, which is just cool.</p>
<p>OK, so we&#8217;re aware of what a strongly typed view would look like and the benefits of it. How can we do it? Well, we can roll our own (which has been done in a few places very nicely but is quite a bit of work), we can use the basic ones provided in the MVC Futures assembly (which provide pretty much the same functionality, look, and feel as the existing ones in System.Web.Mvc but with the strong typed goodness), or we can use the ones included in the open source <a href="http://www.codeplex.com/MVCContrib">MVC Contrib</a> project. This is a project that provides a lot of really nice &#8220;glue&#8221; to help out with any ASP.NET MVC project, taking advantage of many of the extensibility points built into the framework already.</p>
<p>Unfortunately, it looks like the latest release download doesn&#8217;t include the Fluent Html assembly (fluent html is what most people use when referring to this strong typed HTML tag output because it&#8217;s a &#8220;fluent&#8221; interface, as you&#8217;ll see shortly). You&#8217;ll need to build the project from source, so grab the latest copy at <a href="http://mvccontrib.googlecode.com/svn/trunk">http://mvccontrib.googlecode.com/svn/trunk</a>, then run the <i>ClickToBuild</i> batch file in the root folder. It&#8217;ll do it&#8217;s thing, then when it&#8217;s finished you&#8217;ll need to grab the following files in the newly created <strong>buildnet-3.5.win32-MVCContrib-release</strong> folder:</p>
<ul>
<li>MvcContrib.dll</li>
<li>MvcContrib.pdb (optional - provides line numbers if you need to debug anything)</li>
<li>MvcContrib.xml (method and parameter comments)</li>
<li>MvcContrib.FluentHtml.dll</li>
<li>MvcContrib.FluentHtml.pdb</li>
<li>MvcContrib.FluentHtml.xml</li>
</ul>
<p>In the next part I&#8217;ll go over the basic usage of the library, then in the third part I&#8217;ll cover some of the cooler aspects, like tying it into validation and other things.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/04/30/strongly-typed-views-with-mvc-contrib-part-1/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/04/30/strongly-typed-views-with-mvc-contrib-part-1/</feedburner:origLink></item>
		<item>
		<title>jTemplates - Client-Side Templating With jQuery</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/bEOMwblysoo/</link>
		<comments>http://darrell.mozingo.net/2009/04/30/jtemplates-client-side-templating-with-jquery/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 13:15:41 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=23</guid>
		<description><![CDATA[We&#8217;re using ASP.NET MVC on my current project at work, and we&#8217;re heavily exploring jQuery and other client side tools for AJAX effects. One of the first areas where we needed it was a screen where the user enters a zip code and a list of various values get returned based on that code. We [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re using ASP.NET MVC on my current project at work, and we&#8217;re heavily exploring jQuery and other client side tools for AJAX effects. One of the first areas where we needed it was a screen where the user enters a zip code and a list of various values get returned based on that code. We got it working just fine rather quickly, but only by slinging some nasty looking spaghetti code in the JavaScript, so we started looking around for a possible solution.</p>

<p>One of the first things we stumbled on was <a href="http://jtemplates.tpython.com/">jTemplates</a>, a client side templating plug-in for jQuery. Awesomeness. So lets say we have the following action on our Employee controller:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> ActionResult LookupPeopleByZip<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> zip<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	var peopleInZip <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008000;">new</span> Person
				<span style="color: #000000;">&#123;</span>
					Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;John&quot;</span>,
					Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">25</span>
				<span style="color: #000000;">&#125;</span>,
			<span style="color: #008000;">new</span> Person
				<span style="color: #000000;">&#123;</span>
					Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Jane&quot;</span>,
					Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">30</span>
				<span style="color: #000000;">&#125;</span>,
			<span style="color: #008000;">new</span> Person
				<span style="color: #000000;">&#123;</span>
					Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Mike&quot;</span>,
					Age <span style="color: #008000;">=</span> <span style="color: #FF0000;">21</span>
				<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">return</span> Json<span style="color: #000000;">&#40;</span>peopleInZip<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>



<p>This creates a simple list of Person objects, uses the built-in ASP.NET MVC JSON result builder to serialize the object graph, and returns that JSON string. Now, let&#8217;s look at one possible, and probably more common, way to display these results in a table from an AJAX call:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost:35125/Standard/LookupPeopleByZip/'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#zipCode&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>
				<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>allMatches<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> matchCount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #003366; font-weight: bold;">var</span> tableHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;table&gt;'</span> <span style="color: #339933;">+</span>
									<span style="color: #3366CC;">'&lt;tr&gt;'</span> <span style="color: #339933;">+</span>
										<span style="color: #3366CC;">'&lt;th&gt;Name&lt;/th&gt;'</span> <span style="color: #339933;">+</span>
										<span style="color: #3366CC;">'&lt;th&gt;Age&lt;/th&gt;'</span> <span style="color: #339933;">+</span>
									<span style="color: #3366CC;">'&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> allMatches<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						matchCount<span style="color: #339933;">++;</span>
&nbsp;
						tableHtml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;tr&gt;'</span> <span style="color: #339933;">+</span>
									<span style="color: #3366CC;">'&lt;td&gt;'</span> <span style="color: #339933;">+</span> allMatches<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #000066;">Name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/td&gt;'</span> <span style="color: #339933;">+</span>
									<span style="color: #3366CC;">'&lt;td&gt;'</span> <span style="color: #339933;">+</span> allMatches<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">Age</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/td&gt;'</span> <span style="color: #339933;">+</span>
								 <span style="color: #3366CC;">'&lt;/tr&gt;'</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
&nbsp;
					tableHtml <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #003366; font-weight: bold;">var</span> headerHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;h3&gt;Matches: '</span> <span style="color: #339933;">+</span> matchCount <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/h3&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#searchResults&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>headerHtml <span style="color: #339933;">+</span> tableHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>



<p>When the search button is clicked, we use jQuery&#8217;s <code>getJSON</code> method to call out to our action depicted above. The resulting JSON string is constructed into an object graph and passed into our call back method (named allMatches above). We then piece meal our HTML together, looping through the object as needed and writing out the properties.</p>
<p>In the solution download at the end, you&#8217;ll see it runs just fine. Snappy and everything. Damn that&#8217;s some ugly Javascript code though, isn&#8217;t it? This is all for a very simple two column table - just imagine something of even moderate complexity here. Instead, let&#8217;s take a look at the jTemplates solution:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#search&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://localhost:35125/JTemplates/LookupPeopleByZip/'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#zipCode&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>
				<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>allMatches<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#searchResults'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setTemplateURL</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/Content/ResultTemplate.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#searchResults'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">processTemplate</span><span style="color: #009900;">&#40;</span>allMatches<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>



<p>Just a wee-bit smaller, wouldn&#8217;t you say? This code is mostly the same as the original, but instead of building the needed HTML template inline, it uses the jTemplates provided methods on the jQuery selector to set the location for our template, and execute it with our allMatches collection. The template referenced above, ResultTemplate.html, is a basic HTML snippet intermingled with a very minimalistic script like language that jTemplates parses out and updates appropriately:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;h3&gt;Matches: {$T.length}&lt;/h3&gt;
&nbsp;
&lt;table&gt;
	&lt;tr&gt;
		&lt;th&gt;Name&lt;/th&gt;
		&lt;th&gt;Age&lt;/th&gt;
	&lt;/tr&gt;
&nbsp;
	{#foreach $T as match}
		&lt;tr&gt;
			&lt;td&gt;{$T.match.Name}&lt;/td&gt;
			&lt;td&gt;{$T.match.Age}&lt;/td&gt;
		&lt;/tr&gt;
	{#/for}
&lt;/table&gt;</pre></td></tr></table></div>



<p>The syntax is actually pretty similar to the <a href="http://sparkviewengine.com/">Spark view engine</a>. It simply loops through the passed in parameter (<code>$T</code>) and prints out the needed properties. Notice there&#8217;s a few extra properties dangling off the parameter too, such as length, used to show the match count at the top.</p>
<p>That&#8217;s pretty much the basics. Sort of an output only MVC pattern for Javascript (with the JSON return being the model, the return call method being the controller, and jTemplates providing the view engine). If you take a look through the jTemplates site you&#8217;ll see there&#8217;s quite a bit more to it if needed. Its come in handy in a few places on our project so far. Grab the <a href="/wp-content/uploads/2009/04/jtemplates.zip">sample solution here</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/04/30/jtemplates-client-side-templating-with-jquery/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/04/30/jtemplates-client-side-templating-with-jquery/</feedburner:origLink></item>
		<item>
		<title>Freedom or mentoring?</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/cnqeExehYew/</link>
		<comments>http://darrell.mozingo.net/2009/04/08/freedom-or-mentoring/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 12:09:54 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=110</guid>
		<description><![CDATA[Let&#8217;s take a hypothetical here and say you&#8217;re looking at two jobs. They&#8217;re at roughly similar companies which we&#8217;ll call Company A and Company B (I know, I know, original, right?). You&#8217;d be working on similar projects at either and they both have comparable co-workers. For all intents and purposes they&#8217;re equal, save for one [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s take a hypothetical here and say you&#8217;re looking at two jobs. They&#8217;re at roughly similar companies which we&#8217;ll call Company A and Company B (I know, I know, original, right?). You&#8217;d be working on similar projects at either and they both have comparable co-workers. For all intents and purposes they&#8217;re equal, save for one glaring difference:</p>


<ul>
		<li>Company A gives you more freedom to &#8220;explore&#8221;. You&#8217;re more or less given time to read up on things, try new technologies &amp; methodologies knowing full well some will fail and basically waste time (and given some extra slack in your schedule to compensate), get some extra training here and there, and not have a pink slip waived in front of you if you happen to let a few bugs through to production.</li>
		<li>Company B has one or more senior developers that honestly love their craft, push continous learning, and can mentor you in advanced - and &#8220;proper&#8221; - directions and techniques. Test driven development? Check. SOLID principals and their real-world application? Check. Domain driven design? Check. I&#8217;m not just talking about guys that have read up on these topics either, but that have years of experience in them and a metric crap load of failures under their belts that they&#8217;re willing to share inorder to help insure you don&#8217;t fall into them too. They take pride in all aspects of their job and won&#8217;t stand for letting things slide.</li>
</ul>


<p>Which would you choose?</p>

<p>It&#8217;s tough. The benefits Company A provides could get you to the same end goal as Company B, albeit at a slower pace. Company B would presumably be stricter on slip-ups and time management, so if you&#8217;re using a technology you&#8217;re not terribly interested in or you&#8217;re taking a route you don&#8217;t agree with, there&#8217;s not much you can do without working on your dime.</p>

<p>You&#8217;re not guaranteed to ever reach that same end goal with Company A as you would with Company B, though. Self learning is a difficult, slippery slope. You have to encounter all those failures yourself and actually overcome them. Granted, failing for yourself teaches you something more than just hearing a warning from a mentor, but those failures take time, and I believe there&#8217;s a quote about these situations&#8230; something along the lines of &#8220;Those who fail to learn from history, are doomed to repeat it&#8221;, I believe.</p>

<p>Me, personally? I&#8217;m not sure. I can see it both ways, though I&#8217;ve only had the pleasure (?) of working with companys similar Company A. It&#8217;s a tough decision, and my answer probably depends on what day you ask me. I know I&#8217;d like to see what the other side of the fence has to offer though.</p>

<p>What&#8217;s your take?</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/04/08/freedom-or-mentoring/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/04/08/freedom-or-mentoring/</feedburner:origLink></item>
		<item>
		<title>Layout tweaks</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/WMylme-8rU8/</link>
		<comments>http://darrell.mozingo.net/2009/03/09/layout-tweaks/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 02:07:46 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Quickie]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=99</guid>
		<description><![CDATA[OK, maybe not so much tweaks as borderline major reconstruction. I change the layout to give it a fluid width and replaced my syntax highlighter, which was getting on my nerves, with a new one that appears to be working much better. Time will tell, though.

If you&#8217;re reading this through an RSS reader (and honestly, [...]]]></description>
			<content:encoded><![CDATA[<p>OK, maybe not so much tweaks as borderline major reconstruction. I change the layout to give it a fluid width and replaced my syntax highlighter, which was getting on my nerves, with a new one that appears to be working <em>much</em> better. Time will tell, though.</p>

<p>If you&#8217;re reading this through an RSS reader (and honestly, who isn&#8217;t?), the code samples should be a bit more legible, and less mangled up for no good reason, going forward. If by some chance my touching up all the previous posts relisted them as new in your reader - and it hasn&#8217;t for Google Reader - then I apologize. I&#8217;m done now, I hope.</p>

<p>Anyway, on to more actual posts.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/03/09/layout-tweaks/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/03/09/layout-tweaks/</feedburner:origLink></item>
		<item>
		<title>2009 Goals - March Update</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/CjsktriY2QU/</link>
		<comments>http://darrell.mozingo.net/2009/03/01/2009-goals-march-update/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 01:30:30 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[Goals]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=44</guid>
		<description><![CDATA[We&#8217;re 1/6th of the way through 2009. How am I doing on my goals for the year? Let&#8217;s see (comments in italics after each goal):
Books
I&#8217;ll be honest, I haven&#8217;t been too good on the book front. I was already about half way through Jimmy Nilsson&#8217;s Applying Domain Driven Design when I made these goals, and [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re 1/6th of the way through 2009. How am I doing on my <a href="http://darrell.mozingo.net/2009/01/02/new-year-new-goals-2009/">goals for the year</a>? Let&#8217;s see (comments in italics after each goal):</p>
<h3>Books</h3>
<p>I&#8217;ll be honest, I haven&#8217;t been too good on the book front. I was already about half way through Jimmy Nilsson&#8217;s <a href="http://www.amazon.com/Applying-Domain-Driven-Design-Patterns-Examples/dp/0321268202">Applying Domain Driven Design</a> when I made these goals, and figured I&#8217;d finish it, then move on to the next book. Well, then I realized I&#8217;d probably be better off reading Evan&#8217;s Domain Driven Design book first, so I put down Nilsson&#8217;s version. I need to pick up the pace on the reading front, so I think I&#8217;ll commit to a certain number of pages each night, even if small, so there&#8217;s always some forward progress.</p>
<h3>Tools/Techniques/Processes @ Work</h3>
<ul>
    <li><strike>NHibernate and all its trimmings (FluentNHibernate, LINQ to NHibernate, etc), which I&#8217;ll need on a project here real soon.</strike>&nbsp; <em>I think I can say this one is slain. We&#8217;re successfully using all three tools widescale in our project, and I&#8217;m learning more about them each day that passes.</em></li>
    <li>Actually move from CC.NET to Team City (last attempt didn&#8217;t go so well).&nbsp; <em>No progress.</em></li>
    <li>Build a more robust build script and management process - including production deployment scenarios.&nbsp;&nbsp; <em>Other than some tinkering around, no real progress.</em></li>
    <li>Messaging framework, either <a href="http://code.google.com/p/masstransit/">MassTransit</a>, <a href="http://www.nservicebus.com/">NServiceBus</a>, or Ayende&#8217;s new <a href="http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx">Rhino Service Bus</a> if he&#8217;s able to release it in time for our current project.&nbsp; <em>No progress as we haven&#8217;t needed any yet.</em></li>
</ul>
<h3>Involvement</h3>
<ul>
    <li>We have weekly meetings to catch everyone up on what we&#8217;re doing, but I want to present on an actual topic during at least 2 of these - and present in a way where the other development teams will see the use in picking up the presented tool/technique.&nbsp;&nbsp;&nbsp; <em>My group did a quick ~ one hour presentation on NHibernate, but we did virtually no pre-planning, so it was sort of rushed through and I think went over most of the other developer&#8217;s heads. I need to plan a presentation out next time and bite off a smaller chunk to talk about.</em></li>
    <li>Have at least one meeting of the <a href="http://www.cantonalt.net">CantonALT.NET</a> group and see if it can ever get up on its feet.&nbsp;&nbsp; <em>No progress.</em></li>
    <li>The two blog posts per month target John put out there seems doable, so I&#8217;ll borrow it :)&nbsp;&nbsp;&nbsp; <em>So far so good - at least 2 each month.</em></li>
    <li>At least 3 feature/patch submissions to open source projects.&nbsp; <em>No progress, but I think I&#8217;m going to stretch myself and look at submitting a patch to Linq for NHibernate to support date part comparisons (ie TransactionDate.Year == 2009). It currently blows up on that.</em></li>
</ul>
<h3>Productivity</h3>
<ul>
    <li>Trim RSS feed size by 1/3 (presently at 127, so trim it to at least 85) and cut time viewing it by half. I&#8217;ve gotten much better this past year at cutting through the useless stuff, but there&#8217;s still a lot there and it sucks up too much of my time.&nbsp; <em>Still at 127, though some are from Craigslist searches for items I&#8217;m looking for, so I did drop a few unread development blogs.</em></li>
</ul>
<p>All in all I think I&#8217;m doing a bit below par. I&#8217;m behind on the reading, but everything else isn&#8217;t too bad, as they&#8217;re longer term goals. I need to decide on the next action for each of these to get them moving.</p>
<p>How&#8217;s everyone else doing with their goals?</p>
<p>I&#8217;ll update again in the begining of May.</p>]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/03/01/2009-goals-march-update/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/03/01/2009-goals-march-update/</feedburner:origLink></item>
		<item>
		<title>ELMAH with ASP.NET MVC</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/fwmgazPApow/</link>
		<comments>http://darrell.mozingo.net/2009/02/19/elmah-with-aspnet-mvc/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 15:27:53 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=37</guid>
		<description><![CDATA[We finally got to the point of needing some error reporting in our new application. We&#8217;d read about ELMAH before and assumed we&#8217;d use that, but that was a while before we decided to go with the ASP.NET MVC framework instead of the traditional WebForms.
I was a little worried we&#8217;d hit some road block using [...]]]></description>
			<content:encoded><![CDATA[<p>We finally got to the point of needing some error reporting in our new application. We&#8217;d read about <a href="http://code.google.com/p/elmah/">ELMAH</a> before and assumed we&#8217;d use that, but that was a while before we decided to go with the ASP.NET MVC framework instead of the traditional WebForms.</p>
<p>I was a little worried we&#8217;d hit some road block using ELMAH in conjunction with ASP.NET MVC, but it actually works out of the box without a hitch. ELMAH has a built in module for displaying any logged errors, and is accessible (by default) via <code>http://localhost/elmah.axd</code>. The latest releases of ASP.NET MVC automatically ignore routes with a .axd extension, though I&#8217;m not sure for how many releases they&#8217;ve been including that, so earlier releases will have a problem getting to that URL.</p>
<p>Simone Busoli wrote up an <a href="http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx">excellent article</a> on the most important features of ELMAH and getting it setup. A must read if you&#8217;re going to implement this solution.</p>
<p>Here&#8217;s a quick run-down of the steps we went through for our application, though (using SQL logging &amp; emailing the developers whenever an exception is logged):</p>
<ol>
<li>Reference the ELMAH.dll assembly in your project.</li>
<li>Define the section group in your web.config:


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sectionGroup</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;elmah&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;security&quot;</span> <span style="color: #000066;">requirePermission</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.SecuritySectionHandler, Elmah&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;errorLog&quot;</span> <span style="color: #000066;">requirePermission</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.ErrorLogSectionHandler, Elmah&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;errorMail&quot;</span> <span style="color: #000066;">requirePermission</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.ErrorMailSectionHandler, Elmah&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sectionGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>



</li>
<li>Define the needed ELMAH section elements, along with their related SQL connection string, in your web.config (we&#8217;re only allowing access to the error page via the local host):


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;elmah<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security</span> <span style="color: #000066;">allowRemoteAccess</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;errorLog</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.SqlErrorLog, Elmah&quot;</span> <span style="color: #000066;">connectionStringName</span>=<span style="color: #ff0000;">&quot;ErrorLogging&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;errorMail</span></span>
<span style="color: #009900;">        <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;PPError@PatriotSoftware.com&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;PPDevs@SynergyDataSystems.com&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">subject</span>=<span style="color: #ff0000;">&quot;Patriot Pay Error&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">async</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">smtpPort</span>=<span style="color: #ff0000;">&quot;25&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">smtpServer</span>=<span style="color: #ff0000;">&quot;imail.topechelon.corp&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/elmah<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connectionStrings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ErrorLogging&quot;</span> <span style="color: #000066;">connectionString</span>=<span style="color: #ff0000;">&quot;Data Source=....&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connectionStrings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>



</li>
<li>Add the follow handler to the <code><httpHandlers></code> section that&#8217;ll allow you to view the errors (I used the path errors.axd instead of the default elmah.axd, just because I hate using default URL like that in case we ever allow this on something other than localhost w/a restricted login):


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">verb</span>=<span style="color: #ff0000;">&quot;POST,GET,HEAD&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;errors.axd&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.ErrorLogPageFactory, Elmah&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>



</li>
<li>Add the following modules to the <code><httpModules></code> section, which will actually catch exceptions for logging to SQL and emailing out:


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ErrorLog&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.ErrorLogModule, Elmah&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ErrorMail&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;Elmah.ErrorMailModule, Elmah&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>



</li>
<li>(Optional) Add the following methods to your <code>Global.asax</code>, which will filter all exceptions thrown on the local host and ignore them (so developing on your local machine won&#8217;t keep emailing everyone else, which, trust me, gets old pretty damn quick):


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> errorLog_Filtering<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ExceptionFilterEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>ErrorFiltering.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> HttpContextWrapper<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Context</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        e.<span style="color: #0000FF;">Dismiss</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> errorMail_Filtering<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ExceptionFilterEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>ErrorFiltering.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> HttpContextWrapper<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Context</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        e.<span style="color: #0000FF;">Dismiss</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>



<p>and in another file somewhere (note the HttpContextWrapper in both of these pieces of code, for easier testing):</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ErrorFiltering
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">bool</span> Filter<span style="color: #000000;">&#40;</span>HttpContextWrapper httpContextWrapper<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> httpContextWrapper.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">IsLocal</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>



</li>
<li>Run the SQL script included with the ELMAH download to generate the needed table and stored procedures, then hookup SQL security and the connection string from the previous steps</li>
</ol>
<p>You should be good to go now, ripe with error logging goodness. For added user friendliness, we use the following in our web.config to redirect users to nice pages when an error pops up:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customErrors</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;RemoteOnly&quot;</span> <span style="color: #000066;">defaultRedirect</span>=<span style="color: #ff0000;">&quot;~/Errors/Generic.html&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;error</span> <span style="color: #000066;">statusCode</span>=<span style="color: #ff0000;">&quot;404&quot;</span> <span style="color: #000066;">redirect</span>=<span style="color: #ff0000;">&quot;~/Errors/NotFound.html&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;error</span> <span style="color: #000066;">statusCode</span>=<span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">redirect</span>=<span style="color: #ff0000;">&quot;~/Errors/Internal.html&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customErrors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>



<p>The <em>only</em> thing that buggs me about using ELMAH is how Resharper acts with it. The SectionHandler&#8217;s defined in the sectionGroup in the web.config (from step 2 above) are internal to the ELMAH assembly, so Resharper freaks out that saying they&#8217;re not defined. Bzzt. Sorry, Resharper, try again. So I&#8217;ve simply built a local version of the project with those attributes marked as public and it&#8217;s all good. I&#8217;m looking into filing a bug report with Resharper on this issue now, as it does it with log4net too. Quite annoying when you have the Solution-wide Analysis option turned on and the web.config consistently shows up with &#8220;errors&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/02/19/elmah-with-aspnet-mvc/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/02/19/elmah-with-aspnet-mvc/</feedburner:origLink></item>
		<item>
		<title>Generic NHibernate User Type Base Class</title>
		<link>http://feeds.mozingo.net/~r/TallerCode/~3/Y_kpKMz8qOY/</link>
		<comments>http://darrell.mozingo.net/2009/02/10/generic-nhibernate-user-type-base-class/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 15:11:13 +0000</pubDate>
		<dc:creator>Darrell Mozingo</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://darrell.mozingo.net/?p=36</guid>
		<description><![CDATA[NHibernate allows you to create custom types for situations where you need more than what&#8217;s provided by default (int, string, decimal, etc). For example, we have a custom Money, Percent, and Hour value types in our domain which are, for the most part, immutable generic wrappers around a decimal. We wanted to store these types [...]]]></description>
			<content:encoded><![CDATA[<p>NHibernate allows you to create custom types for situations where you need more than what&#8217;s provided by default (int, string, decimal, etc). For example, we have a custom Money, Percent, and Hour value types in our domain which are, for the most part, immutable generic wrappers around a decimal. We wanted to store these types as decimals in the database, but using the provided decimal type just wouldn&#8217;t work.</p>
<p>Reading <a href="http://intellect.dk/">Jakob Andersen&#8217;s</a> nice short article on <a href="http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx">creating custom NHibernate user types</a> gave us the solution we needed, and after creating user types for those three values types, I quickly began getting bored with the repetitiveness of it all.</p>
<p>I figured we&#8217;d have a few more user types for the project, so I decided to refactor out as much as I could from the user types themselves. The result is a generic base class that handles all the mundane details of implementing an NHibernate user type:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> abstract <span style="color: #FF0000;">class</span> BaseImmutableUserType<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> <span style="color: #008000;">:</span> IUserType
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> abstract <span style="color: #FF0000;">object</span> NullSafeGet<span style="color: #000000;">&#40;</span>IDataReader rs, <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> names, <span style="color: #FF0000;">object</span> owner<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> abstract <span style="color: #0600FF;">void</span> NullSafeSet<span style="color: #000000;">&#40;</span>IDbCommand cmd, <span style="color: #FF0000;">object</span> value, <span style="color: #FF0000;">int</span> index<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">public</span> abstract SqlType<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> SqlTypes <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">bool</span> Equals<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> x, <span style="color: #FF0000;">object</span> y<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>ReferenceEquals<span style="color: #000000;">&#40;</span>x, y<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">||</span> y <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">return</span> x.<span style="color: #0000FF;">Equals</span><span style="color: #000000;">&#40;</span>y<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> GetHashCode<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> x<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> x.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> DeepCopy<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> value<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> value<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> Replace<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> original, <span style="color: #FF0000;">object</span> target, <span style="color: #FF0000;">object</span> owner<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> original<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> Assemble<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> cached, <span style="color: #FF0000;">object</span> owner<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> DeepCopy<span style="color: #000000;">&#40;</span>cached<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> Disassemble<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> value<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> DeepCopy<span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> Type ReturnedType
	<span style="color: #000000;">&#123;</span>
		get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> IsMutable
	<span style="color: #000000;">&#123;</span>
		get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>



<p>Pretty much boiler plate code. This allows us to specify just what we need in each user type&#8217;s implementation, such as this one for our Money value type:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MoneyUserType <span style="color: #008000;">:</span> BaseImmutableUserType<span style="color: #008000;">&lt;</span>Money<span style="color: #008000;">&gt;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">object</span> NullSafeGet<span style="color: #000000;">&#40;</span>IDataReader rs, <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> names, <span style="color: #FF0000;">object</span> owner<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var amount <span style="color: #008000;">=</span> NHibernateUtil.<span style="color: #FF0000;">Decimal</span>.<span style="color: #0000FF;">NullSafeGet</span><span style="color: #000000;">&#40;</span>rs, names<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">To</span><span style="color: #008000;">&lt;</span><span style="color: #FF0000;">decimal</span><span style="color: #008000;">?&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> amount.<span style="color: #0000FF;">ToMoney</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> NullSafeSet<span style="color: #000000;">&#40;</span>IDbCommand cmd, <span style="color: #FF0000;">object</span> value, <span style="color: #FF0000;">int</span> index<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var moneyObject <span style="color: #008000;">=</span> value <span style="color: #0600FF;">as</span> Money<span style="color: #008000;">;</span>
		<span style="color: #FF0000;">object</span> valueToSet<span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>moneyObject <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			valueToSet <span style="color: #008000;">=</span> moneyObject.<span style="color: #0000FF;">Amount</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">else</span>
		<span style="color: #000000;">&#123;</span>
			valueToSet <span style="color: #008000;">=</span> DBNull.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		NHibernateUtil.<span style="color: #FF0000;">Decimal</span>.<span style="color: #0000FF;">NullSafeSet</span><span style="color: #000000;">&#40;</span>cmd, valueToSet, index<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> SqlType<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> SqlTypes
	<span style="color: #000000;">&#123;</span>
		get
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span>
			       	<span style="color: #000000;">&#123;</span>
			       		SqlTypeFactory.<span style="color: #FF0000;">Decimal</span>
			       	<span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>



<p>Refactoring out all the unneeded junk, as simple as it might have been, allows other developers to get a quicker grasp of the system and small pieces in it. I know I hate having to break down a large class with lots of unneeded code in it, and this base class allows us to reduce the actual user type down enough to view on a single screen.</p>
<p>This also allowed us to reduce the tests we were doing on each user type to three: one for the get and set methods, and one for the SqlTypes property. All the base class&#8217; functionality can be tested separately, and only once. Less tests (while still maintaining adequate coverage) = easier comprehension = lower maintenance costs.</p>
<p>In a future post I&#8217;ll show a test fixture base class we use to easily test each user type.</p>
]]></content:encoded>
			<wfw:commentRss>http://darrell.mozingo.net/2009/02/10/generic-nhibernate-user-type-base-class/feed/</wfw:commentRss>
		<feedburner:origLink>http://darrell.mozingo.net/2009/02/10/generic-nhibernate-user-type-base-class/</feedburner:origLink></item>
	</channel>
</rss>
