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

<channel>
	<title>Elegant Code &#187; Patterns and Practices</title>
	<atom:link href="http://elegantcode.com/tag/patterns-and-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Sat, 11 Feb 2012 04:39:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Code Cast 13 &#8211; Microsoft Patterns and Practices</title>
		<link>http://elegantcode.com/2008/09/02/code-cast-13-microsoft-patterns-and-practices/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-cast-13-microsoft-patterns-and-practices</link>
		<comments>http://elegantcode.com/2008/09/02/code-cast-13-microsoft-patterns-and-practices/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 04:14:00 +0000</pubDate>
		<dc:creator>David Starr</dc:creator>
				<category><![CDATA[CodeCast]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Code Cast]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Patterns and Practices]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/09/02/code-cast-13-microsoft-patterns-and-practices/</guid>
		<description><![CDATA[Chris and David were lucky enough to sit down (okay, it was a conference call) with Grigori Melnik and Ajoy Krishnamoorthy from Microsoft’s Patterns and Practices. Grigori and Ajoy covered a wide range of topics including Agile development practices within P&#38;P, what P&#38;P has to offer the community, and forthcoming products from the team. Show [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://microsoftpdc.com/" target="_blank"><img src="http://www.microsoftpdc.com/Images/BlogBling/Bling3.jpg" alt="" align="right" /></a> Chris and David were lucky enough to sit down (okay, it was a conference call) with Grigori Melnik and Ajoy Krishnamoorthy from Microsoft’s Patterns and Practices. Grigori and Ajoy covered a wide range of topics including Agile development practices within P&amp;P, what P&amp;P has to offer the community, and forthcoming products from the team.</p>
<p><strong>Show Links</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/agile/">Grigori Melnik’s Blog</a></li>
<li><a href="http://blogs.msdn.com/ajoyk/">Ajoy Krishnamoorthy’s Blog</a></li>
<li><a href="http://msdn.microsoft.com/practices">Microsoft P&amp;P Team Site</a></li>
<li><a href="http://codeplex.com/TestingGuidance">Acceptance Test Engineering Guidance</a></li>
<li><a href="http://channel9.msdn.com/posts/Charles/Tour-Patterns-and-Practices-Lab/">P&amp;P Team Room Video</a></li>
<li><a href="http://msdn.microsoft.com/en-us/practices/bb232643.aspx">P&amp;P Upcoming Releases</a></li>
<li><a href="http://www.pnpsummit.com/_practices.aspx">Patterns and Practices Summit</a>, November 3-7, 2008</li>
</ul>
<p><a href="http://pluralsight-free.s3.amazonaws.com/david-starr/ecc/ECC_13_MS_PatternsAndPractices.mp3">Download the episode MP3</a></p>
<p><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=271207118"><img src="http://elegantcode.com/cast/files/images/itunes_button.gif" border="0" alt="View in iTunes" /></a> <a href="http://feeds.feedburner.com/elegantcodecast"><img src="http://elegantcode.com/cast/files/images/rss_podcast.jpg" border="0" alt="Any Podcatcher" /></a></p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:103d8226-f879-4268-877a-01eac008542a" class="wlWriterSmartContent" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/Micrososft+P%26P">Micrososft P&amp;P</a>,<a rel="tag" href="http://technorati.com/tags/Agile">Agile</a>,<a rel="tag" href="http://technorati.com/tags/Patterns+and+Practices">Patterns and Practices</a>,<a rel="tag" href="http://technorati.com/tags/.Net">.Net</a></div>
<p><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=39d5550f-2b51-4176-8f5c-cd4d82122c93" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/09/02/code-cast-13-microsoft-patterns-and-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://pluralsight-free.s3.amazonaws.com/david-starr/ecc/ECC_13_MS_PatternsAndPractices.mp3" length="31363377" type="audio/mpeg" />
		</item>
		<item>
		<title>Unity 1.0 EventBroker Sample CAB Style</title>
		<link>http://elegantcode.com/2008/04/09/unity-10-eventbroker-sample-cab-style/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=unity-10-eventbroker-sample-cab-style</link>
		<comments>http://elegantcode.com/2008/04/09/unity-10-eventbroker-sample-cab-style/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 06:55:52 +0000</pubDate>
		<dc:creator>Scott Nichols</dc:creator>
				<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Open Source Software]]></category>
		<category><![CDATA[Patterns and Practices]]></category>
		<category><![CDATA[Tools and Utilities]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/04/09/unity-10-eventbroker-sample-cab-style/</guid>
		<description><![CDATA[Ok so Unity 1.0 has shipped, or should I say the “Unity Application Block” as Microsoft is terming it now. However, in this post I am not going to talk about the Unity IoC contain but a pretty cool peace of code that comes bundled with Unity’s QuickStart samples, the Event Broker Extension. The Event [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so <a href="http://www.codeplex.com/unity">Unity 1.0</a> has shipped, or should I say the “Unity Application Block” as Microsoft is terming it now. However, in this post I am not going to talk about the Unity <a href="http://en.wikipedia.org/wiki/Inversion_of_Control">IoC</a> contain but a pretty cool peace of code that comes bundled with Unity’s QuickStart samples, the Event Broker Extension.</p>
<p>The Event Broker Extension QuickStart demonstrates how you can extend the Unity container by adding a custom extension. The QuickStart implements an Event Broker for the container as a container extension and demonstrates the new extension using the StopLight QuickStart application sample.</p>
<p>The Event Broker Extension QuickStart contains three projects:</p>
<ul>
<li><strong>EventBroker</strong>. This project implements a simple publish and subscribe mechanism that supports multiple event publishers and multiple subscribers.</li>
<li><strong>EventBrokerExtension</strong>. This project implements the custom container extension that allows applications to publish and subscribe to events using attributes or explicitly using code.</li>
<li><strong>StopLight</strong>. This project is basically the same as that described in the Unity StopLight QuickStart, but it uses the custom container extension to manage the publishing of, and subscription to, two events within the application.</li>
</ul>
<p>Now, why is this Unity EventBroker interesting? Well, if you have ever worked with <a href="http://www.cabpedia.com/index.php?title=Composite_UI_Application_Block">CAB</a> (Composite UI Application Block) or <a href="http://www.cabpedia.com/index.php?title=Smart_Client_Software_Factory">SCSF</a> (Smart Client Software Factory) then you know one of its main pillars was the implementation of a nice Pub/Sub event subscription framework which Microsoft called Event Broker. This was one of the best things about CAB. Unfortunately with CAB it is an all or nothing deal. You really cannot use the CAB Event Broker without using the rest of the CAB underpinnings.</p>
<p>The Unity implementation of the Event Broker is similar to CABs so you should feel right at home if you have any experience with CAB or SCSF. The one huge benefit is that the Unity Event Broker can easily be integrated into any existing WinForm or WPF application where you would like an easy to manage Event bus to handle all your event traffic.</p>
<p>It really is easy to implement, lets take a look at what you need to do in order to integrate the Unity based Event Broker into your application.</p>
<p>1) Download <a href="http://www.codeplex.com/unity">Unity 1.0</a> install it and unzip the “Unity QuickStart” package found in the Unity start menu installation path.</p>
<p>2) Compile the EventBrokerExtention and SimpleEventBroker projects.  Then grab the following DLLs found in the EventBrokerExtention bin folder and reference them in your application.<br />
  EventBrokerExtension.dll<br />
  SimpleEventBroker.dll<br />
  Microsoft.Practices.ObjectBuilder2.dll<br />
  Microsoft.Practices.Unity.dll</p>
<p>3) Now open your WinForm application and modify your entry point usually the Program.cs file which in my demo calls the FormMain.cs using a Unity Container like so.</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Windows.Forms;
<span class="kwrd">using</span> EventBrokerExtension;
<span class="kwrd">using</span> Microsoft.Practices.Unity; 

<span class="kwrd">namespace</span> SampleWinApp
{
    <span class="kwrd">static</span> <span class="kwrd">class</span> Program
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// The main entry point for the application.</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        [STAThread]
        <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(<span class="kwrd">false</span>); 

            <span class="rem">// Create parent container</span>
            IUnityContainer mainContainer = <span class="kwrd">new</span> UnityContainer()
                  .AddNewExtension&lt;EventBrokerBusExtension&gt;(); 

            Application.Run(mainContainer.Resolve&lt;FormMain&gt;());
        }
    }
}</pre>
<p>The important thing to notice is that I have wired up the EventBrokerExtention class through the Unity AddNewExtention method.  This will cause all the Events that are properly decorated with the correct attributes to be automatically registered in the EventBroker or SimpleEventBroker class.</p>
<p>You will also want to go and modified all the areas in your code where you are opening other forms to use a Unity container as well.  Here is an example opening a Form called FromA.cs </p>
<pre class="csharpcode"><span class="rem">//Create container</span>
IUnityContainer myContainer = <span class="kwrd">new</span> UnityContainer()
           .AddNewExtension&lt;EventBrokerBusExtension&gt;();
<span class="rem">//Open Form</span>
FormA newForm = myContainer.Resolve&lt;FormA&gt;();
newForm.Show();</pre>
<style type="text/css">    .csharpcode, .csharpcode pre  {  	font-size: small;  	color: black;  	font-family: consolas, "Courier New", courier, monospace;  	background-color: #ffffff;  	/*white-space: pre;*/  }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #006080; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt   {  	background-color: #f4f4f4;  	width: 100%;  	margin: 0em;  }  .csharpcode .lnum { color: #606060; }</style>
<p>Oh, make sure you import the proper libraries on all your forms.</p>
<pre class="csharpcode"><span class="kwrd">using</span> Microsoft.Practices.Unity;
<span class="kwrd">using</span> EventBrokerExtension;
<span class="kwrd">using</span> SimpleEventBroker;</pre>
<p>Now you need to setup all the Event publications and triggers. Let’s start simple, say we have a button on our FormMain that is used to force a data refresh in your application. You would need to add a publish event to your page like so.</p>
<pre class="csharpcode"><span class="rem">//Using an attribute register an event in the EventBroker</span>
[Publishes(<span class="str">"RefreshData"</span>)]
<span class="kwrd">public</span> <span class="kwrd">event</span> EventHandler RefreshData ;
<span class="rem">//Method you will call to trigger the event in the EventBroker </span>
<span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> OnRefreshDataChange(<span class="kwrd">object</span> sender, EventArgs ea)
{
    EventHandler handlers = RefreshData ;
    <span class="kwrd">if</span> (handlers != <span class="kwrd">null</span>)
    {
        handlers(<span class="kwrd">this</span>, EventArgs.Empty);
    }
}</pre>
<p>On your button click trigger the event like so.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">void</span> buttonRefresh_Click(<span class="kwrd">object</span> sender, EventArgs e)
{
    <span class="rem">//Trigger your event </span>
    OnRefreshDataChange(<span class="kwrd">this</span>, e);
}</pre>
<p>Now you need to setup all your Event subscriptions, this is supper easy.  You will need to create a method on all the forms in your application that will handle your refresh command i.e. implements the functionality you wish for each form or control in your application.  So far in this contrived example I have two forms FormMain and FormA.  You would add a method like so to each page.    </p>
<pre class="csharpcode">[SubscribesTo(<span class="str">"RefreshData"</span>)]
<span class="kwrd">public</span> <span class="kwrd">void</span> OnRefreshDataFired(<span class="kwrd">object</span> sender, EventArgs e)
{
         <span class="rem">//Do something, we need to do a data refresh</span>
}</pre>
<style type="text/css">    .csharpcode, .csharpcode pre  {  	font-size: small;  	color: black;  	font-family: consolas, "Courier New", courier, monospace;  	background-color: #ffffff;  	/*white-space: pre;*/  }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #006080; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt   {  	background-color: #f4f4f4;  	width: 100%;  	margin: 0em;  }  .csharpcode .lnum { color: #606060; }</style>
<p>Now anytime the RefreshData button is pushed the event is fired and all objects subscribed to that event in the EventBroker will be triggered. </p>
<p>One important step you will want to do is unregister your subscribed events every time a modal form is closed.  Remember we are using the Unity IoC container to open a form which automatically registers all publisher and subscriber event handles on form_load (opened). </p>
<pre class="csharpcode"><span class="rem">// Unregister your subscription to help prevent runtime errors</span>
<span class="kwrd">private</span> <span class="kwrd">void</span> FormA_FormClosing(<span class="kwrd">object</span> sender, FormClosingEventArgs e)
{
     EventBroker myEB = <span class="kwrd">new</span> EventBroker();
     myEB.UnregisterSubscriber(<span class="str">"RefreshData"</span>, OnRefreshDataFired);
}</pre>
<p>That is about it, I used this to clean up an old legacy application that had Window events thrown everywhere.  The SimpleEventBroker class has several methods you can use to monitor what is going on inside the EventBroker such as GetPublisher, GetSubscribers, etc.</p>
<p>Oh, in my implementation I modified the Dictionary in the SimpleEventBroker class which holds the registered published events to be static, makes it easier if you have lots of modal forms, just make sure the Keys (string values) are unique.</p>
<pre class="csharpcode">

<span class="kwrd">public</span> <span class="kwrd">class</span> EventBroker
    {
        <span class="kwrd">private</span> <span class="kwrd">static</span> Dictionary&lt;<span class="kwrd">string</span>, PublishedEvent&gt; eventPublishers  

        = <span class="kwrd">new</span> Dictionary&lt;<span class="kwrd">string</span>, PublishedEvent&gt;();</pre>
<style type="text/css">    .csharpcode, .csharpcode pre  {  	font-size: small;  	color: black;  	font-family: consolas, "Courier New", courier, monospace;  	background-color: #ffffff;  	/*white-space: pre;*/  }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #006080; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt   {  	background-color: #f4f4f4;  	width: 100%;  	margin: 0em;  }  .csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/04/09/unity-10-eventbroker-sample-cab-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is Elegant Code to me?</title>
		<link>http://elegantcode.com/2008/03/30/what-is-elegant-code-to-me/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-is-elegant-code-to-me</link>
		<comments>http://elegantcode.com/2008/03/30/what-is-elegant-code-to-me/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 03:47:45 +0000</pubDate>
		<dc:creator>Chris Brandsma</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Patterns and Practices]]></category>
		<category><![CDATA[Widgets of Wisdom]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/03/30/what-is-elegant-code-to-me/</guid>
		<description><![CDATA[This question keeps popping up around here (&#8220;around here&#8221; being the loose conglomeration that makes up the Elegant Code group).&#160; It isn&#8217;t easy to describe.&#160; And really, the notion of what constitutes elegance in code changes over time.&#160; There is no static &#8220;this is good code&#8221; test, and I doubt there ever will be.&#160; Plus, [...]]]></description>
			<content:encoded><![CDATA[<p>This question keeps popping up around here (&#8220;around here&#8221; being the loose conglomeration that makes up the Elegant Code group).&nbsp; It isn&#8217;t easy to describe.&nbsp; And really, the notion of what constitutes elegance in code changes over time.&nbsp; There is no static &#8220;this is good code&#8221; test, and I doubt there ever will be.&nbsp; Plus, what makes good code in one language, may not apply to the next.</p>
<p>So let me state for the record: today&#8217;s elegant code is tomorrow&#8217;s drivel.&nbsp; Don&#8217;t feel bad, many writers have the same problems.&nbsp; What was super amazing back in the day is now rubbish or near unreadable.&nbsp; I am thinking of the Victorian writing that Hemingway usurped, and now Hemingway himself is almost unreadable (to me anyway).&nbsp; Tastes change with the times.&nbsp; That is a simple fact.</p>
<p>So what can you do about this?&nbsp; As I say that old writing sucks to read (read Washington Irvine lately?), great works of literature still abound (for instance, Hemingway is still a great writer &#8212; even if I prefer Tolkien) .&nbsp; So take some notes from them, and from other crafts in looking for the answer.&nbsp; If you want a cliff notes version of what this is going to tell you, it is this: you must always push yourself to get better.</p>
<ol>
<li>Find a good teacher.&nbsp; Nothing is better than sitting at the feet of a master who can nudge you along in the right direction.&nbsp; While early mistakes can often be corrected easily with a little bit of guidance, after they have had some time to fester all bets are off.&nbsp; I believe a fare number of &#8220;Anit-patterns&#8221; were created by self taught developers (find <a href="http://elegantcode.com/2008/03/21/sql-ejaculation/">SQL Ejaculation</a> on this site).&nbsp;
<li>Read.&nbsp;&nbsp; Good writer are first good readers.&nbsp; Start with Code Complete, move into a good Patterns book, get MSDN Magazine, find some bloggers your like, but keep moving.&nbsp; You will NEVER be done reading.&nbsp; I imagine that even Martin Fowler has a &#8220;to read&#8221; booklist a mile long.
<li>Read code.&nbsp;&nbsp; There are a plethora of open source project just waiting to be read &#8212; do so.&nbsp; This is the single best way to expand your coding repertoire, find things your language can do that you didn&#8217;t even know about..&nbsp;&nbsp; Scott Hanselman has recently popularized this idea, and I thank him for it.
<li>Practice.&nbsp; This means writing small applications at home.&nbsp; You get an idea that you want to try out &#8212; do it.&nbsp; I don&#8217;t mean you have to write finished applications, just have some exploring time.&nbsp; I remember talking with an 80 year old master woodworker (he lives down the street from me), who was telling me how many time he would practice making dovetail joints before he felt competent.&nbsp; It was years worth.
<li>Pay Attention.&nbsp; Being good at anything really amounts to that.&nbsp; And don&#8217;t just pay attention when reading, writing, or talking about code.&nbsp; Inspiration come from everywhere, any good artist will tell you that.&nbsp; Pay attention when you cook, when you work on the car, when you are wood working, playing an instrument, whatever it is that you do.&nbsp; This will help you in the end, event if it is just learning the amount of dedication it really takes to become good at something.
<li>Beware of preferences.&nbsp; Any time I hear someone start a statement with &#8220;I prefer code to &#8230;&#8221; you know things are going downhill.&nbsp; If you find someone who cares more about how your code is formatted then how it is written you have found yourself in a mess.&nbsp; More importantly, beware of them in yourself.&nbsp;&nbsp; Having code style standard is important, but it isn&#8217;t worth loosing sleep over.&nbsp; This also pertains to inheritance, patterns, use of particular classes (e.g. always using the generic list class in C# when a Dictionary would be better).&nbsp;
<li>No Sacred Cows. Believe no single source of information.&nbsp; This means not thinking that Microsoft, Sun, IBM, Richard Stallman, or anyone else will have all of the correct answers.&nbsp; Apply the scientific method and do some research, experiment, and question the authority.&nbsp;&nbsp; There should be no sacred cows in programming.
<li>Talk with others.&nbsp; Join a user group, show up every now and then, heckle the presenter, and -maybe- speak.&nbsp; You want a broad range of people who you can talk to and bounce ideas off of.&nbsp; This will help you from becoming that crazy guy in the corner who vehemently states that all your code should be in one file.&nbsp; Having a mentor (mentioned earlier) is great, but having people around to push you from multiple directions is also good.
<li>Learn languages.&nbsp; This gets back to the &#8220;read code&#8221; idea. Make that multiple types of languages as well.&nbsp; If you know C# or Java and SQL, learn Python or Ruby, get really good at JavaScript.&nbsp; If you want something really out there, learn MDX.&nbsp; This is also a repertoire thing.&nbsp; Seeing how other languages work will make you rethink your ideas about what your current code, in whatever languages you are working in, should look like.
<li>Keep Thinking!!!&nbsp; That is possibly the most important point.&nbsp; Keep thinking.&nbsp; Don&#8217;t just evaluate something once and never return, go back and reevaluate. Did the technique work?&nbsp; How could it have been better?&nbsp;&nbsp; The idea is continual improvement.
<li>Switch jobs every now and then.&nbsp; When I announced I was leaving my first programming job out of college, the VP of R&amp;D had me sit down with him and talk.&nbsp; He wasn&#8217;t trying to keep me (he knew I was moving to be closer to family), he wanted to give me some advice.&nbsp; He told me to change jobs every three years.&nbsp; After you have been with a place for three years you have probably learned everything you are going to learn and it time to move on.&nbsp; This doesn&#8217;t mean changing companies either.&nbsp; I&#8217;ve been with the same company now for four years, but I&#8217;ve had three different jobs.&nbsp; If you have been writing commercial applications, become a consultant &#8211; or vise-versa, become a test engineer, expand your boundaries.&nbsp; Again, this is about pushing yourself to be better.
<li>Have a Hobby. But don&#8217;t ask about me, I have too many.&nbsp;&nbsp; Creating software is about creating things.&nbsp; So I suggest picking a hobby that involves creating something.&nbsp; Popular hobbies amongst programmers I know include: cooking, music, woodworking, beer making, and BBQ (which is different than cooking).&nbsp; But don&#8217;t discount sports (golf is always popular), computer games, and board games.&nbsp; Anything that promotes the development of skill levels can&#8217;t be a bad thing. </li>
</ol>
<p>And I&#8217;m stopping there.&nbsp; This is my beginner&#8217;s guide to how to become the writer elegant code.&nbsp; If you have others you think I missed, add them too the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/03/30/what-is-elegant-code-to-me/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Cast 5 &#8211; Matt Milner</title>
		<link>http://elegantcode.com/2008/03/15/elegant-code-cast-5-is-online/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=elegant-code-cast-5-is-online</link>
		<comments>http://elegantcode.com/2008/03/15/elegant-code-cast-5-is-online/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 19:13:42 +0000</pubDate>
		<dc:creator>David Starr</dc:creator>
				<category><![CDATA[CodeCast]]></category>
		<category><![CDATA[Code Cast]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Patterns and Practices]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/03/15/elegant-code-cast-5-is-online/</guid>
		<description><![CDATA[This week&#8217;s Elegant Code Cast is an interview with Matt Milner of PluralSight and MSDN Magazine. Matt is an amazing presenter and fount of knowledge on WCF, WF, and BizTalk. He drops some great knowledge on these subjects and enterprise SOA, along with some discussion of Oslo, Microsoft&#8217;s new Model Driven initiative. PluralSight Matt&#8217;s Blog [...]]]></description>
			<content:encoded><![CDATA[<p>This week&#8217;s Elegant Code Cast is an interview with Matt Milner of <a href="http://pluralsight.com">PluralSight </a>and MSDN Magazine.</p>
<p>Matt is an amazing presenter and fount of knowledge on WCF, WF, and BizTalk. He drops some great knowledge on these subjects and enterprise SOA, along with some discussion of Oslo, Microsoft&#8217;s new Model Driven initiative.</p>
<ul>
<li><a href="p://www.pluralsight.com/default.aspx" target="_blank">PluralSight</a></li>
<li><a href="http://www.pluralsight.com/blogs/matt/" target="_blank">Matt&#8217;s Blog</a></li>
<li><a href="http://www.microsoft.com/soa/products/oslo.aspx" target="_blank">Oslo</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/netframework/aa663324.aspx" target="_blank">Windows Communication Foundation</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/netframework/aa663328.aspx">Windows Workflow</a></li>
<li><a href="http://www.microsoft.com/biztalk/default.mspx" target="_blank">Microsoft BizTalk</a></li>
</ul>
<p><a href="http://pluralsight-free.s3.amazonaws.com/david-starr/ecc/ECC_05_MattMilner.mp3">Download the episode MP3</a></p>
<p><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=271207118"><img src="http://elegantcode.com/cast/files/images/itunes_button.gif" border="0" alt="View in iTunes" /></a> <a href="http://feeds.feedburner.com/elegantcodecast"><img src="http://elegantcode.com/cast/files/images/rss_podcast.jpg" border="0" alt="Any Podcatcher" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/03/15/elegant-code-cast-5-is-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://pluralsight-free.s3.amazonaws.com/david-starr/ecc/ECC_05_MattMilner.mp3" length="36546768" type="audio/mpeg" />
		</item>
		<item>
		<title>Boise Code Camp 2008</title>
		<link>http://elegantcode.com/2008/03/09/boise-code-camp-2008/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=boise-code-camp-2008</link>
		<comments>http://elegantcode.com/2008/03/09/boise-code-camp-2008/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 02:25:35 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Architecture and Design]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Code Camp]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Patterns and Practices]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/03/09/boise-code-camp-2008/</guid>
		<description><![CDATA[Boise Code Camp 2008 was awesome. Thank you to David Starr and his wife, Eleanor, for taking ownership of this event and dedicating many months of their time to make this a reality. Thank you to the presenters for having the passion and desire to present technologies and practices, both new and not-as-new. Thank you [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Boise Code Camp 2008" href="http://www.boisecodecamp.org/" target="_blank">Boise Code Camp 2008</a> was awesome. Thank you to <a title="David Starr" href="http://elegantcode.com/about/david-starr/" target="_blank">David Starr</a> and his wife, <a title="Domestic Oblivion" href="http://domesticoblivion.com/" target="_blank">Eleanor</a>, for taking ownership of this event and dedicating many months of their time to make this a reality. Thank you to the presenters for having the passion and desire to present technologies and practices, both new and not-as-new. Thank you to the many volunteers who put in countless hours to help coordinate the weekend&#8217;s events. Thank you to the campers for attending and making this year&#8217;s code camp a success.</p>
<p>I am sure everyone will be blogging about all the great sessions they attended at code camp. I enjoyed all of the presentations I attended, and I am excited to explore some new material. </p>
<p>I want to share a few thoughts on my presentation dealing with Model-View-Presenter in ASP.NET after listening to <a title="Scott Hanselman" href="http://www.hanselman.com" target="_blank">Scott Hanselman&#8217;s</a> session on the <a title="ASP. NET MVC Project" href="http://www.asp.net/mvc" target="_blank">ASP.NET MVC Project</a>. I may have the percentage incorrect, but Scott mentioned something like it is predicted that only 10% of the ASP.NET community currently using Web Forms will adopt and use the MVC framework. The MVC framework is an addition to ASP.NET, it is not a replacement. What this means is that Model-View-Presenter will still be a viable pattern to implement with your ASP.NET applications, and it is not going away. ASP.NET Web Forms will not be going away either.</p>
<p>Use MVP to get your third party controls under test. Use MVP to provide that separation of concerns in your legacy applications. Use it entirely or in conjunction with the MVC framework. It is all about testability. <a title="Glenn Block" href="http://blogs.msdn.com/gblock/" target="_blank">Glenn Block</a> presented on the Web Client Software Factory, and what pattern does this implement? Model-View-Presenter.</p>
<p>I am providing my <a title="Presentation and Source Code" href="http://muellerdesigns.net/DasBlog/content/binary/ModeViewPresenter.AlexMueller.BoiseCodeCamp2008.rar" target="_blank">presentation and source code (3.67 MB)</a> from my talk on MVP. It will be available via the <a title="Boise Code Camp" href="http://www.boisecodecamp.org/" target="_blank">Boise Code Camp</a> site as well. </p>
<p>Again, thank the many individuals and their families who sacrificed their time to bring to the local community this years code camp.</p>
<p>Around the office&#8217;s water cooler on Monday, I will be able to say, &quot;and this one time, at code camp&#8230;&quot;</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/03/09/boise-code-camp-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Cast 3 &#8211; Chris Brandsma</title>
		<link>http://elegantcode.com/2008/02/18/elegant-code-cast-episode-3-is-online/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=elegant-code-cast-episode-3-is-online</link>
		<comments>http://elegantcode.com/2008/02/18/elegant-code-cast-episode-3-is-online/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 19:33:30 +0000</pubDate>
		<dc:creator>David Starr</dc:creator>
				<category><![CDATA[CodeCast]]></category>
		<category><![CDATA[Architecture and Design]]></category>
		<category><![CDATA[C# 3.0]]></category>
		<category><![CDATA[Code Cast]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[Patterns and Practices]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/02/18/elegant-code-cast-episode-3-is-online/</guid>
		<description><![CDATA[In this episode of the Elegant Code Cast, we visit with Elegant Coder Chris Brandsma. Chris is a senior developer at Mobile Data Force in Boise, Idaho. Chris provides some great details on subjects ranging from AJAX and RIA separation of concerns to LINQ and Lambda expressions. He also gives us a glimpse of what [...]]]></description>
			<content:encoded><![CDATA[<p>In this episode of the Elegant Code Cast, we visit with Elegant Coder Chris Brandsma. Chris is a senior developer at Mobile Data Force in Boise, Idaho. Chris provides some great details on subjects ranging from AJAX and RIA separation of concerns to LINQ and Lambda expressions.</p>
<p>He also gives us a glimpse of what it is like to live your life visiting other people&#8217;s development shops. Did you know source control is stil optional in some organizations?</p>
<p>Chris is a true code craftsman and this shows in his clear explanations of some very advanced programming concepts. If you haven&#8217;t played with Lambda expressions, anonymous delegates, or LINQ, start with this podcast.</p>
<p><a href="http://pluralsight-free.s3.amazonaws.com/david-starr/ecc/ECC_03_ChrisBrandsma.mp3">Download the episode MP3</a></p>
<p><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=271207118"><img src="http://elegantcode.com/cast/files/images/itunes_button.gif" border="0" alt="View in iTunes" /></a> <a href="http://feeds.feedburner.com/elegantcodecast"><img src="http://elegantcode.com/cast/files/images/rss_podcast.jpg" border="0" alt="Any Podcatcher" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/02/18/elegant-code-cast-episode-3-is-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://pluralsight-free.s3.amazonaws.com/david-starr/ecc/ECC_03_ChrisBrandsma.mp3" length="38813673" type="audio/mpeg" />
		</item>
		<item>
		<title>Microsoft releases Unity, an IoC library</title>
		<link>http://elegantcode.com/2008/02/17/microsoft-releases-unity-an-ioc-library/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=microsoft-releases-unity-an-ioc-library</link>
		<comments>http://elegantcode.com/2008/02/17/microsoft-releases-unity-an-ioc-library/#comments</comments>
		<pubDate>Mon, 18 Feb 2008 03:41:42 +0000</pubDate>
		<dc:creator>Chris Brandsma</dc:creator>
				<category><![CDATA[Architecture and Design]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Patterns and Practices]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/02/17/microsoft-releases-unity-an-ioc-library/</guid>
		<description><![CDATA[Here is a bit of interesting news out of Microsoft.&#160; They have released their first IoC container named Unity.&#160; It is out on CodePlex now: http://www.codeplex.com/unity If you are looking for a similar product with a longer lineage, you could look up: StructureMap, Spring.Net, and Castle Windsor.&#160; StructureMap is maintained by Jeremy Miller, who is [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a bit of interesting news out of Microsoft.&nbsp; They have released their first IoC container named Unity.&nbsp; It is out on CodePlex now: <a href="http://www.codeplex.com/unity">http://www.codeplex.com/unity</a></p>
<p>If you are looking for a similar product with a longer lineage, you could look up: <a href="http://structuremap.sourceforge.net/Default.htm">StructureMap</a>, <a href="http://www.springframework.net/">Spring.Net</a>, and <a href="http://www.castleproject.org/container/">Castle Windsor</a>.&nbsp; StructureMap is maintained by <a href="http://codebetter.com/blogs/jeremy.miller/">Jeremy Miller</a>, who is a favorite blogger of mine (everyone should read his series on <a href="http://codebetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own-cab-series-table-of-contents.aspx">Build your own CAB</a>).&nbsp; Spring.Net is a port of an existing Java project, and Castle Windsor seems to have a lot of mind share.&nbsp; Currently, Spring.Net is the only IoC library that I have used.</p>
<p>OK, definitions: <br />IoC: Inversion of Control, also called Dependency Injection.<br />This is based on a pattern found in the Gang Of Four books on Design Patterns.<br />You can read more about this pattern at Martin Fowlers web site:<br /><a href="http://martinfowler.com/articles/injection.html">http://martinfowler.com/articles/injection.html</a><br />Or on Wikipedia:<br /><a href="http://en.wikipedia.org/wiki/Inversion_of_control">http://en.wikipedia.org/wiki/Inversion_of_control</a></p>
<p>The basic principle that IoC is used for is Loose Coupling.&nbsp; If you have a multi-layered application, each layer should not have to know specific details about the other layers.&nbsp; So each object in a specific layer will implement an interface that the IoC provider knows about.&nbsp; Then, when a specific dependency is needed, you ask the IoC container for it (note: the IoC container is Tightly coupled) for the object to do the work.&nbsp;&nbsp; If you look at the Asp.Net Membership Provider, you can see a simple example of that at work.</p>
<p>One of the ways that this can help you is that now all of your middle pieces can be swapped out without having to make massive code changes.&nbsp; This also makes testing easier, as now you can more easily stub/mock/fake dependencies and just test your application logic.</p>
<p>Also, if you really get into the whole IoC thing, you will find that there are a number of other cool Computer Sciency things are possible.&nbsp; Like Aspect Oriented Programming (unknown if Unity supports that or not).</p>
<p><em>Now with all of the other IoC libraries out there, why would I like the fact that Microsoft has created their own?&nbsp; <br /></em>One of the current issues with a lot of Microsoft software, especially the samples, is that they are all VERY tightly coupled (again, tight coupling is not good), but it is a pain to get around without an IoC solution.&nbsp; And, as per Microsoft&#8217;s own structure, they will not use any software that they didn&#8217;t write or own.&nbsp;&nbsp; So I&#8217;m hopeful that now they can start producing some software with loose coupling in mind, and make all of our lives easier.</p>
<p>All right, there are still a lot of definitions and ideas that could leave you puzzled, that happens.&nbsp; That is also why we have google.&nbsp; If you see something you don&#8217;t understand, leave a comment and I&#8217;ll try to clarify, or point you to someone else with a better explanation than I can give.</p>
<p>Finally, if you are looking for more information on this sort of thing, check out the session on Castle Windsor at <a href="http://BoiseCodeCamp.com">Boise Code Camp</a> on March 8.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/02/17/microsoft-releases-unity-an-ioc-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WCSF Validation Tweaks</title>
		<link>http://elegantcode.com/2008/01/29/wcsf-client-side-validation-tweaks/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wcsf-client-side-validation-tweaks</link>
		<comments>http://elegantcode.com/2008/01/29/wcsf-client-side-validation-tweaks/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 09:28:19 +0000</pubDate>
		<dc:creator>Jarod Ferguson</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Patterns and Practices]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/01/29/wcsf-client-side-validation-tweaks/</guid>
		<description><![CDATA[We recently implemented the Validation Bundle from P&#38;P. The Bundle consists of the VAB PropertyProxyValidator from EntLib, as well as a custom ASP.NET AJAX control extender which provides the client callback support. For the most part the Bundle rocks, but there are a few things which didn&#8217;t meet our needs: The default PropertyProxyValidator inherits from [...]]]></description>
			<content:encoded><![CDATA[<p>We recently implemented the <a href="http://www.codeplex.com/websf/Wiki/View.aspx?title=Validation_landing_page&amp;referringTitle=Home">Validation Bundle</a> from P&amp;P. The Bundle consists of the VAB PropertyProxyValidator from EntLib, as well as a custom ASP.NET AJAX control extender which provides the client callback support. </p>
<p>For the most part the Bundle rocks, but there are a few things which didn&#8217;t meet our needs:</p>
<ol>
<li>The default PropertyProxyValidator inherits from System.Web.UI.WebControls.BaseValidator, like the other Asp.Net validators. This makes it great for mixing all types of standard Validators (Like Regex or RequiredField), but has a major drawback for Client side validation because it validates on every PostBack (full) as well as Callback (partial). </li>
<li>On a full postback, such as a form submit, the ServerSideValidationExtender issues a Callback request to the Validator </li>
<li>Even if the value had not changed, validation still occurs. </li>
</ol>
<h3>A simple scenario</h3>
<p>We have an Organization with two fields, Name &amp; Code</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2008/01/image12.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="99" alt="image" src="http://elegantcode.com/wp-content/uploads/2008/01/image-thumb6.png" width="244" border="0" /></a> </p>
<p>Lets look at the validation events:</p>
<ul>
<li>Enter Name &#8216;Bob&#8217;s Plumbing&#8217;, Press Tab (or click off)
<ul>
<li>Callback: Validation occurs for Name </li>
</ul>
</li>
<li>Enter Code &#8216;BPL&#8217;, Press Tab (or click off)
<ul>
<li>Callback: Validation occurs for Code </li>
</ul>
</li>
<li>Click Save
<ul>
<li>Callback: Validation occurs for Name </li>
<li>Callback: Validation occurs for Code </li>
<li>Postback (full): Validation Occurs for Name &amp; Code </li>
</ul>
</li>
</ul>
<p>So we have validated each property 3 times. This might be OK we were just parsing for special characters, but in our case we also want to call a service and see if these values already exist in our system: 3x is too expensive.</p>
<p>Aside from being expensive, this is a unique type of validation where we want to check if a condition isn&#8217;t true (Org Name doesn&#8217;t exist) vs. is true. (an valid email address or a valid state) </p>
<p>This makes point #3 above especially troubling for our scenario, because if we want to edit this Organization in the future, any time we change a value, all the rest of the validators will fire and come back invalid as they already exist.</p>
<p>Example updating just the Org Code, which causes the Name to validate:</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2008/01/image13.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="66" alt="image" src="http://elegantcode.com/wp-content/uploads/2008/01/image-thumb7.png" width="244" border="0" /></a> </p>
<p>&#160;</p>
<h3>The Solution</h3>
<ul>
<li>Kill the full postback validation with OnCallBackPropertyProxyValidator </li>
<li>Modify ServerSideValidationExtender to *only* validate if the value has changed </li>
</ul>
<h4>OnCallBackPropertyProxyValidator </h4>
<p>OnCallBackPropertyProxyValidator is a pretty quick fix. We will just inherit the ProperyProxyValidator and kick out of the EvaluateIsValid method if its not a CallBack.</p>
<p>&#160;</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span>&#160;&#160;&#160; <span style="color: #008000">/// &lt;summary&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>    <span style="color: #008000">/// Class which only performs validation when page is in a callback state</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>    <span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> OnCallBackPropertyProxyValidator : PropertyProxyValidator</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>    {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>        <span style="color: #008000">/// &lt;summary&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>        <span style="color: #008000">/// If Page.IsCallBack, determines whether the content in the input control is valid.</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>        <span style="color: #008000">/// &lt;/summary&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>        <span style="color: #008000">/// &lt;returns&gt;&lt;see langword=&quot;true&quot;/&gt; if the control is valid; otherwise, &lt;see langword=&quot;false&quot;/&gt;.&lt;/returns&gt;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">bool</span> EvaluateIsValid()</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>        {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>            <span style="color: #0000ff">if</span> (!<span style="color: #0000ff">this</span>.Page.IsCallback)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>            {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>                <span style="color: #0000ff">this</span>.ErrorMessage = <span style="color: #006080">&quot;&quot;</span>;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>                <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>            }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>            <span style="color: #0000ff">else</span> </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>            {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>                <span style="color: #0000ff">return</span> <span style="color: #0000ff">base</span>.EvaluateIsValid();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>            }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>        }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>    }</pre>
</p></div>
</div>
<p>&#160;</p>
<h4>ServerSideValidation </h4>
<p>Well add the &#8216;only-validate-if-value-changed&#8217; functionality by fetching the current text value from the control to be validated, storing the property in JSON, and then evaluating if the value has changed before requesting validation from the server.</p>
<p>&#160;</p>
<h5>Modifying the ServerSideValidationExtender.cs </h5>
<p>Add the CurrentValue Property to the Extender C# class:</p>
<p>&#160;</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> [ExtenderControlProperty]</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> [ClientPropertyName(<span style="color: #006080">&quot;currentValue&quot;</span>)]</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> [DefaultValue(<font color="#0000ff">&quot;&quot;</font>)]</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> CurrentValue</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     get { <span style="color: #0000ff">return</span> GetPropertyValue&lt;<span style="color: #0000ff">string</span>&gt;(<span style="color: #006080">&quot;CurrentValue&quot;</span>, <span style="color: #0000ff">string</span>.Empty); }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     set { SetPropertyValue&lt;<span style="color: #0000ff">string</span>&gt;(<span style="color: #006080">&quot;CurrentValue&quot;</span>, <span style="color: #0000ff">value</span>); }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span> }</pre>
</p></div>
</div>
<p>Set the current value in OnPreRender:</p>
<p>&#160;</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnPreRender(EventArgs e)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>         <span style="color: #0000ff">base</span>.OnPreRender(e);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>        </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         Omitted code here....        </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>&#160; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>         <span style="color: #008000">// Set the current Text value</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         Control controlToValidate = extendedValidator.NamingContainer.FindControl(extendedValidator.ControlToValidate);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>         ITextControl textControl = controlToValidate <span style="color: #0000ff">as</span> ITextControl;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>         <span style="color: #0000ff">if</span> (textControl != <span style="color: #0000ff">null</span>)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>         {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>             CurrentValue = textControl.Text;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>         }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>         Omitted code here...</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>     }</pre>
</p></div>
</div>
<p>&#160;</p>
<h5>Modifying the ServerSideValidationBehavior.js Behavior</h5>
<p>Add the CurrentValue property to the descriptor:</p>
<p>&#160;</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> AjaxControlToolkit.WCSFExtensions.ServerSideValidationBehavior.descriptor = {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>    properties: [   {name: <span style="color: #006080">'callbackControl'</span>, type: String},</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>                    {name: <span style="color: #006080">'validateEmptyText'</span>, type: Boolean},</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>                    <font color="#ff0000">{name: <span style="color: #006080">'currentValue'</span>, type: String} ]</font></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> }</pre>
</p></div>
</div>
<p>Add the accessor methods to the prototype:</p>
<p>&#160;</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> get_currentValue: function(){</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.currentValue;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> },</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> set_currentValue: function(<span style="color: #0000ff">value</span>){</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     <span style="color: #0000ff">this</span>.currentValue = <span style="color: #0000ff">value</span>;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span> }</pre>
</p></div>
</div>
<p>And finally check to see if the value has changed </p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> Validate: function() {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     var valueToValidate = <span style="color: #0000ff">this</span>._getValueToValidate();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>&#160; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     Omitted....</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>&#160; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>     <span style="color: #0000ff">if</span> (valueToValidate === <span style="color: #0000ff">this</span>.get_currentValue()) {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>     Omitted.... </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span> },</pre>
</p></div>
</div>
<p>And that&#8217;s it. What we end up with is client side validation which only occurs when the value is changed on the client, through a callback, and no where else. All other validation works in tandem as expected, such as the standard ASP.NET validators, PropertyProxyValidator, or a custom validator which performs VAB self validation.</p>
<p>Though the Bundle didn&#8217;t do everything we were looking for right out of the box, it was pretty easy to get in there and make work exactly how we wanted. Hats off to P&amp;P for some great guidance.</p>
<p>The source code is <a href="http://elegantcode.com/wp-content/uploads/2008/01/serversidevalidation.zip">here</a>. Its just the files, not a complete working solution, but if you download the WCSF source/ Validation Bundle you should be able to plug it in fairly easily. </p>
<p>&#160;</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b2adb7e4-f6f8-46b9-a8f7-cac3a73454d2" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/Asp.net" rel="tag">Asp.net</a>,<a href="http://technorati.com/tags/WCSF" rel="tag">WCSF</a>,<a href="http://technorati.com/tags/VAB" rel="tag">VAB</a>,<a href="http://technorati.com/tags/Validation" rel="tag">Validation</a></div>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/01/29/wcsf-client-side-validation-tweaks/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MVC at Boise NetDug Tomorrow Night</title>
		<link>http://elegantcode.com/2008/01/16/mvc-at-boise-netdug-tomorrow-night/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mvc-at-boise-netdug-tomorrow-night</link>
		<comments>http://elegantcode.com/2008/01/16/mvc-at-boise-netdug-tomorrow-night/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 04:02:38 +0000</pubDate>
		<dc:creator>David Starr</dc:creator>
				<category><![CDATA[Architecture and Design]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Patterns and Practices]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Team Foundation Server]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/01/16/mvc-at-boise-netdug-tomorrow-night/</guid>
		<description><![CDATA[Anyone in the Boise area can come out and get a taste of the new ASP.Net MVC framework from Microsoft. I will be doing an hour or so on the MVC framework at the local .Net users group. Following the MVC talk, Martin Danner will be doing an hour or so on the fresh new [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone in the Boise area can come out and get a taste of the new ASP.Net MVC framework from Microsoft. I will be doing an hour or so on the MVC framework at the <a href="http://www.netdug.com/" target="_blank">local .Net users group</a>.</p>
<p>Following the MVC talk, <a href="http://www.devrevolution.com/" target="_blank">Martin Danner</a> will be doing an hour or so on the fresh new features found in Team Foundation Server 2008.</p>
<p>I hope to see you there. Let&#8217;s go for a beer after over at <a href="http://www.tablerockbrewpub.com/" target="_blank">Table Rock</a>!</p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ccef7c6b-e370-4a46-b4bc-3ba3e2478067" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/ASP.Net%20MVC" rel="tag">ASP.Net MVC</a></div>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/01/16/mvc-at-boise-netdug-tomorrow-night/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mocking the Model in ASP.Net MVC</title>
		<link>http://elegantcode.com/2008/01/03/mocking-the-model-in-aspnet-mvc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mocking-the-model-in-aspnet-mvc</link>
		<comments>http://elegantcode.com/2008/01/03/mocking-the-model-in-aspnet-mvc/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 05:05:28 +0000</pubDate>
		<dc:creator>David Starr</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Patterns and Practices]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/01/03/mocking-the-model-in-aspnet-mvc/</guid>
		<description><![CDATA[The promise of the new ASP.Net MVC framework is better testability through separation of concerns. With that in mind, some folks are talking about how well that goal is realized with the new framework. One thing that makes testing a little difficult is the fact there is no dependency injection (DI) model built into the [...]]]></description>
			<content:encoded><![CDATA[<p>The promise of the new ASP.Net MVC framework is better testability through separation of concerns. With that in mind, some folks are talking about how well that goal is realized with the new framework. </p>
<p>One thing that makes testing a little difficult is the fact there is no dependency injection (DI) model built into the current CTP. <a href="http://haacked.com/archive/2007/11/27/question-for-you-dependency-injection-buffs.aspx" target="_blank">A recent post by Phil Haack</a> may lead one to speculate that a solution is in the works. A dependency injection model coupled with MVC lets us mock our models and views in more declarative ways.</p>
<p>Instead of waiting for a DI technology, we can use a little elbow grease and roll a pseudo&nbsp; workable pattern ourselves. How can we mock the model? How about this?</p>
<p>1. Use an interface to define your model. Remember? Like you&#8217;re supposed to?</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">namespace</span> MvcApplication.Models</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">interface</span> INWStore</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         List&lt;Category&gt; GetCategories();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>         Category GetCategory(<span style="color: #0000ff">int</span> categoryId);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>&nbsp; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>         List&lt;Product&gt; GetProducts(<span style="color: #0000ff">int</span> categoryID);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>&nbsp; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>         Product GetProduct(<span style="color: #0000ff">int</span> id);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span> }</pre>
</div>
</div>
<p>2. Add a constructor to your controller that takes an instance of the interface as an argument. With your default constructor, just instantiate the internal member.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">namespace</span> MvcApplication.Controllers</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> BaseDataController : Controller</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         INWStore _dbContext;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>&nbsp; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>         <span style="color: #0000ff">public</span> BaseDataController()</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>             _dbContext = <span style="color: #0000ff">new</span> NWStoreDataContext();</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>         }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>&nbsp; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>         <span style="color: #0000ff">public</span> BaseDataController(INWStore dataContext)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>         {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>             _dbContext = dataContext;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>         }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span> }</pre>
</div>
</div>
<p> 3. Mock the model in your unit test and pass it in as an argument to the controller constructor. The MVC framework will use the other constructor.</p>
<p>That&#8217;s all there is to it. This isn&#8217;t new thinking, just a reminder. I was walking through all of the examples and lost sight of this for a little while. </p>
<p>I agree with the MVP debaters that a nicer way to mock the views would be to pass them in as interfaces like we just did to the model, but the solutions being demonstrated by Haack are viable as well.</p>
<p>&nbsp;</p>
<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:eafc61d1-d25c-4d5a-8a27-1af37558af7a" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/MVP" rel="tag">MVP</a>,<a href="http://technorati.com/tags/ASP.Net" rel="tag">ASP.Net</a>,<a href="http://technorati.com/tags/ASP.Net%20MVC" rel="tag">ASP.Net MVC</a>,<a href="http://technorati.com/tags/TDD" rel="tag">TDD</a></div>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/01/03/mocking-the-model-in-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

