<?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>Jon Lebensold &#187; ASP.NET</title>
	<atom:link href="http://lebensold.net/category/aspnet/feed" rel="self" type="application/rss+xml" />
	<link>http://lebensold.net</link>
	<description>thoughts on web development, technology and media</description>
	<lastBuildDate>Tue, 22 Jun 2010 16:04:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Web Programming Languages Are Converging: PHP, Ruby and C#</title>
		<link>http://lebensold.net/random/web-programming-languages-are-converging-php-ruby-and-c</link>
		<comments>http://lebensold.net/random/web-programming-languages-are-converging-php-ruby-and-c#comments</comments>
		<pubDate>Tue, 01 Jul 2008 15:27:31 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/random/web-programming-languages-are-converging-php-ruby-and-c</guid>
		<description><![CDATA[I was poking around the Internet the other day and fell upon Google Trends, a tool which, from what I can gather tracks the growth and decay of popular keywords. While this is by no means a definitive look into the market of C#, Ruby and PHP, I thought it would be interesting to see [...]]]></description>
			<content:encoded><![CDATA[<p>I was poking around the Internet the other day and fell upon <a href="http://trends.google.com">Google Trends</a>, a tool which, from what I can gather tracks the growth and decay of popular keywords. While this is by no means a definitive look into the market of C#, Ruby and PHP, I thought it would be interesting to see how popular these languages are, being web-development languages. </p>
<p><img id="image88" src="http://jon.lebensold.ca/wp-content/uploads/2008/07/Picture%2014.png" alt="C#, Ruby and PHP compared with Google Trends" /></p>
<p>What I find particularly interesting with this graph is <strong>convergence</strong>. PHP is losing its footing as the top dog as the one and only web development language. This preliminary glance into technology popularity doesn't factor "Zend", "Ruby on Rails" and "ASP.NET", which are the framework counterparts that make "PHP", "Ruby" and "C#" suited for enterprise web development.</p>
<p>The state-by-state breakdown is even more peculiar. In every US state except for Washington, PHP is the dominant search keyword. In Washington, it's C#:</p>
<p><img id="image89" src="http://jon.lebensold.ca/wp-content/uploads/2008/07/Picture%2015.png" alt="PHP-Ruby-C# Convergence, state-by-state breakdown" /></p>
<p>If I was an ASP.NET developer, or someone trying to market ASP.NET products, I know I'd start in Washington. Take a look at <a href="http://trends.google.com/trends?q=php%2Cruby%2Cc%23&ctab=0&geo=US&geor=all&date=all&sort=0">the full data at Google Trends</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/random/web-programming-languages-are-converging-php-ruby-and-c/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails: How to smell an immature framework</title>
		<link>http://lebensold.net/main/rails-how-to-smell-an-immature-framework</link>
		<comments>http://lebensold.net/main/rails-how-to-smell-an-immature-framework#comments</comments>
		<pubDate>Fri, 20 Jun 2008 19:33:08 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Commentary]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/uncategorized/rails-how-to-smell-an-immature-framework</guid>
		<description><![CDATA[This last week, I've been battling to get a Rails 1.x application moved to a hosting provider that has graciously upgraded to Rails 2.x. There is no migration documentation to be found aside from a scarce upgrade notes file.
Now this is where the clincher is: Rails is a Ruby FRAMEWORK and yet, the hosting provider [...]]]></description>
			<content:encoded><![CDATA[<p>This last week, I've been battling to get a Rails 1.x application moved to a hosting provider that has graciously upgraded to Rails 2.x. There is no migration documentation to be found aside from a scarce <a href='http://www.slashdotdash.net/articles/2007/12/03/rails-2-upgrade-notes'>upgrade notes file</a>.</p>
<p>Now this is where the clincher is: Rails is a Ruby FRAMEWORK and yet, the hosting provider gets to pick which version I'm running. Obviously, this leads to  a forced migration in a production environment. If they decided to upgrade the Ruby language processor it would be a different story. It seems like the Rails team didn't take a hint from the abomination that was PEAR / PECL due to hosting providers bearing the responsibility of versioning what were essentially early extensions of the PHP language. </p>
<p>Why can't I run my own Rails instance? Well hosting providers are being sold on <b>mod_ruby</b> which is really <b>mod_rails</b>. That's like your hosting provider installing <b>mod_zend_framework</b> and then getting to pick the version as it comes out. Let's not forget that four years ago, Zend didn't exist and Rails was a pet project by an young, but innovative group soon to be known to the world as 37Signals.</p>
<p>What bothers me is that this application is a little over a year old and due to the naming changes in the Rails tree (without graceful failures for deprecated functionality) I'm stuck hunting down why each controller is failing. Thankfully, if you're clever in ASP.NET, you can include a lib/ folder with any binaries required for compilation, and the codebase has matured to the point that migrations only occur at the *.5 release. You have to give Microsoft credit for not breaking backwards compatibility as well. As much as they get burned in the browser wars for this reason, it does mean that you're not forced to unravel the cobwebs on a deployed application and spend a week debugging it after 13 months!</p>
<p>While PHP 5.3 is offering some radical enhancements (like namespaces!) to the PHP language, they're at least waiting until 6.x before dropping some of the painful design decisions (like magic quotes etc...) that were made what is forever (more than 2 years!) by web development standards.</p>
<p>Ultimately, having an Apache module design to work with a specific version of a framework sounds like a mix of concerns. Why does the webserver module need to know the details of how Rails handles it's templating engine, or how it dispatches requests? Why is it so bloody complicated to get standardized rails hosting? Why do people develop in webrick, deploy using FastCGI and then have to deal with mod_ruby. </p>
<p>My suggestion is either buy your own machine, get virtual hosting environment, or wait until the dust settles and a unified development / testing / production environment presents itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/main/rails-how-to-smell-an-immature-framework/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET AJAX Validation using Enterprise Library Validation Block</title>
		<link>http://lebensold.net/development/aspnet-ajax-validation-using-enterprise-library-validation-block</link>
		<comments>http://lebensold.net/development/aspnet-ajax-validation-using-enterprise-library-validation-block#comments</comments>
		<pubDate>Sat, 19 Apr 2008 07:57:24 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/aspnet-ajax-validation-using-enterprise-library-validation-block</guid>
		<description><![CDATA[We all loathe writing validation for form elements, however no web developer would be worth their salt if they didn't incorporate at least server-side validation on forms. The problem arises when we're asked to provide client-side validation. With the ever increasing ubiquity of Javascript adoption due to the recent AJAX craze, I think it's safe [...]]]></description>
			<content:encoded><![CDATA[<p>We all loathe writing validation for form elements, however no web developer would be worth their salt if they didn't incorporate at least server-side validation on forms. The problem arises when we're asked to provide client-side validation. With the ever increasing ubiquity of Javascript adoption due to the recent AJAX craze, I think it's safe to say that we'll see a resurgence of fat-clients built inside a browser. </p>
<p><strong>The Purpose<br />
</strong>As forms become more complex, there is greater incentive to minimize trips to the server. Furthermore, ASP.NET doesn't play nice with dynamically generated controls (something that occurs with any moderate AJAX development. The following is a way of utilizing the tools in the Microsoft ASP.NET framework without rewriting key components (for an example of this, look at the MonoRail project or the new Microsoft MVC framework).</p>
<p>In the Microsoft camp, usually you're encouraged to use validators that let act as decorators to existing ASP.NET textboxes and other form elements. To make matters more complicated, the Patterns and Practices group as well as the AJAX.NET group in Microsoft have competing components for dealing with client-side validation.</p>
<p>I propose a third method that employs a webservice and allows you to dynamically generate your validation through an asynchronous postback of your form to the server. I've been testing this approach and I've been pretty successful thus far:</p>
<p><img src="http://jon.lebensold.ca/wp-content/uploads/2008/04/EnterpriseValidationSuggestion.png" height="80%" width="80% vspace="4" alt="Enterprisevalidationsuggestion" /></p>
<p><strong>On Using a Data Transfer Object (DTO)<br />
</strong>A Data Transfer object is simply a container where you can store a collection of variables in an organized manner. A DTO doesn't have any behaviour, just public properties. For example, an Employee object might have the following properties:</p>
<pre lang="c#" >
	Employee employee = EmployeeRepository.GetNewEmployee();
	employee.HiredAt = DateTime.Now();
	employee.Position = "Sales Manager";
	employee.OfficeExtension = 4556;
</pre>
<p>To simplify things, I use Castleproject's ActiveRecord libraries to create a simple relationship between my database tables and my DTO's.</p>
<p>I've broken down the requests in terms of a linear timeline of events on the page.</p>
<p><strong>Why Bother Mapping to a Data Transfer Object?</strong><br />
The Microsoft Enterprise Library enables you to decorate public properties (as well as methods) with validators. Furthermore, you create custom validators and include them in the same infrastructure that Microsoft provides for its own validators.</p>
<p><strong>1) The page is rendered and delivered to the client's browser</strong>: for the most part, it's just a plain old aspx page. However, I've made certain minor modifications that help later on in the dynamic mapping of a DTO from the form back to the server:</p>
<p>A form element looks something like this:</p>
<pre>&nbsp;
	&lt;ASP:TextBox id=&quot;tbEmployeePosition&quot; dto=&quot;Employee&quot; property=&quot;Position&quot; runat=&quot;server&quot; /&gt;
&nbsp;</pre>
<p>In my form, I've provided two attributes, dto and property, which can be used on in the web service to dynamically map the form elements back to the DTO for validation.</p>
<p><strong>2)</strong> <strong>Use a fake button to post the form asynchronously to a webservice in your project:</strong> all the latest javascript frameworks (my personal favourite is Prototype) support form serialization through utility of helper methods (see $F() in prototype). The JSON object you want to send to the webservice might look like this:</p>
<pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#123;</span> <span style="color: #3366CC;">&quot;EmployeeForm&quot;</span> :
    <span style="color: #66cc66;">&#91;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;id&quot;</span> : <span style="color: #3366CC;">&quot;aspnet_dynamic_form_tbEmployeePosition&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;value&quot;</span> : <span style="color: #3366CC;">&quot;Sales Manager&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;property&quot;</span> : <span style="color: #3366CC;">&quot;Position&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;dto&quot;</span> : <span style="color: #3366CC;">&quot;Employee&quot;</span><span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#93;</span>
&nbsp;
    <span style="color: #66cc66;">&#91;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;id&quot;</span> : <span style="color: #3366CC;">&quot;aspnet_dynamic_form_tbEmployeeOfficeExtension&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;value&quot;</span> : <span style="color: #3366CC;">&quot;4556&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;property&quot;</span> : <span style="color: #3366CC;">&quot;OfficeExtension&quot;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#91;</span> <span style="color: #3366CC;">&quot;dto&quot;</span> : <span style="color: #3366CC;">&quot;Employee&quot;</span><span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><strong>3) The Mapping Layer grabs a DTO from the Repository and maps the values using the Data from the JSON posted to the webservice:</strong> it's very easy to take this data and, using the PropertyInfo class and a bit of type checking, map these values to a DTO. Once their mapped, you can easily run Entlib Validation.</p>
<p><strong>4) The ValidationManager validates the DTO, collects the EntLib Validation messages in a Hashtable: </strong>The Hashtable can have a key / value pair with the submitted form element's ID and the error message associated with the invalid element. Error messages are pulled from the MessageTemplate field in your validator's, whether you're adding attributes, or adding validation through your web.config.</p>
<p><strong>5) The Hashtable is returned to the client</strong>: Microsoft's webservices don't support Hashtables natively, however you can get around this by creating an ArrayList containing string[] objects.</p>
<p><strong>6) The values are inserted back onto the form:</strong> with a Hashtable containing element ID's and their respective messages, it becomes trivial to add these server-side messages to the client-side. In Prototype, it's a matter of <strong>Element.insert( responseJSON[i][0] , { "after" : "&lt;span class='error'&gt;"+responseJSON[i][1] + "&lt;/span&gt;" });</strong> where i corresponds with to the message in the list, 0 is the client's element ID and 1 is the message. </p>
<p><strong>7) The Form is automatically submitted to the server if the form is valid</strong>: if responseJSON is empty, we simply fire the <strong>.click();</strong> on the ASP.NET textbox as though the user did it himself. This means keeping track of the ASP.NET prefix which is added on all IDs that have the <strong>runat="server"</strong> directive. </p>
<p>The beauty of this approach is that it's highly extensible, you could serialize and post any part of your form if you needed to. Furthermore, the mapping that happens when the actual form controls are posted to the server would be nearly identical and the validation would be consolidated into one place. Lastly, you could provide the same error messages on server-side postback of the form (however it would be a little tricky to make them display as easily as it is with the web service.</p>
<p>I'll be providing a Zend sample of this in the week to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/aspnet-ajax-validation-using-enterprise-library-validation-block/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX Autocompleter with Script.aculo.us and an ASP.NET web service</title>
		<link>http://lebensold.net/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service</link>
		<comments>http://lebensold.net/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service#comments</comments>
		<pubDate>Fri, 21 Mar 2008 05:23:34 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://jon.lebensold.ca/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service</guid>
		<description><![CDATA[Yesterday a Microsoft MVP had asked me to provide a better example of using the auto-completer that I had made with an ASP.NET project. In response to this, I'm uploading a project that has a fully-functioning example. The use of a web service instead of the AJAX ASP.NET toolkit allows you to embed your AJAXified [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday a Microsoft MVP had asked me to provide a better example of using the auto-completer that I had made with an ASP.NET project. In response to this, I'm uploading a project that has a fully-functioning example. The use of a web service instead of the AJAX ASP.NET toolkit allows you to embed your AJAXified controls inside of user controls rather than having them bound to a particular page. Furthermore, you can easily customize the script if you so choose.</p>
<p><center><a style="border: 0px none #FFF;" href="/wp-content/uploads/2008/AjaxAutoCompleterASPNET.zip"><img  style="border: 0px none #FFF;"src="/wp-content/uploads/2008/downloadSearchIcon.png" /><br />
<br />
Download Ajax Auto Completer Sample ASP.NET project<br />
</a></center></p>
<p>For example, take a look at line 301 of autocompleter.js:</p>
<pre class="javascript">&nbsp;
  choicesToHtml : <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>choices<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> output = <span style="color: #3366CC;">&quot;
&lt;ul&gt;&quot;</span>;
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>i=<span style="color: #CC0000;">0</span>; i&lt; choices.<span style="color: #006600;">length</span>; i++<span style="color: #66cc66;">&#41;</span>
            output = output + <span style="color: #3366CC;">&quot;
&lt;li&gt;&quot;</span> + choices<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span> + <span style="color: #3366CC;">&quot;&lt;/li&gt;
&nbsp;
&quot;</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> output + <span style="color: #3366CC;">&quot;&lt;/ul&gt;
&nbsp;
&quot;</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>  Because you're actually pulling data from the web service, it would be easy to extend this example to provide a fully nested JSON object with images etc... as part of the auto-completer. I'll provide such an example with the Zend Framework and it's web service components at a later date, however being able to serialize a data structure like the one below would be perfect for an auto-completion web service.</p>
<pre class="javascript">&nbsp;
 <span style="color: #66cc66;">&#123;</span>
     <span style="color: #3366CC;">&quot;headerText&quot;</span>: <span style="color: #3366CC;">&quot;SearchBox Header Text&quot;</span>,
     <span style="color: #3366CC;">&quot;searchCollection&quot;</span>: <span style="color: #66cc66;">&#91;</span>
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
    <span style="color: #3366CC;">&quot;searchResult&quot;</span> : <span style="color: #66cc66;">&#123;</span>
        <span style="color: #3366CC;">&quot;imageSource&quot;</span> : <span style="color: #3366CC;">&quot;product.gif&quot;</span>,
        <span style="color: #3366CC;">&quot;text&quot;</span> : <span style="color: #3366CC;">&quot;my product text&quot;</span>,
        <span style="color: #3366CC;">&quot;url&quot;</span> : <span style="color: #3366CC;">&quot;http://linkToMyProduct/&quot;</span>
    <span style="color: #66cc66;">&#125;</span>,
     <span style="color: #66cc66;">&#93;</span>,
     <span style="color: #3366CC;">&quot;headerText&quot;</span>: <span style="color: #3366CC;">&quot;SearchBox Footer Text&quot;</span>
 <span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>While I have excellent unix-based hosting, I unfortunately don't have an external IIS server that I can publish this out. </p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/ajax-autocompleter-with-scriptaculous-and-an-aspnet-web-service/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVP or MVC or neither?</title>
		<link>http://lebensold.net/development/mvp-or-mvc-or-neither</link>
		<comments>http://lebensold.net/development/mvp-or-mvc-or-neither#comments</comments>
		<pubDate>Sat, 15 Dec 2007 18:06:42 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[poeaa]]></category>

		<guid isPermaLink="false">http://jon.artistsweatshop.com/?p=44</guid>
		<description><![CDATA[Lately I've been doing a lot of research on design patterns for web application development, specifically in the Microsoft ASP.NET technology space. This has led me to thinking a lot about how the developments of the past can better refine Zend's promising future. I find it of particular interest that Zend has made a conscious [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I've been doing a lot of research on design patterns for web application development, specifically in the Microsoft ASP.NET technology space. This has led me to thinking a lot about how the developments of the past can better refine Zend's promising future. I find it of particular interest that Zend has made a conscious effort to deviate from enforcing a particular design pattern. In the original release candidates of the Zend Framework, it appeared as though MVC was the only way to go. Luckily, this is no longer the case, and crafty developers have found creative ways of implementing patterns that encourage testability and larger code bases.</p>
<p>What seems to have been a requirement for contemporary Ruby / Python / PHP developers has really hit home with the C# web development community. It seems that two camps within Microsoft are pushing MVC (Model-View-Controller) and MVP (Model-View-Presenter) separately and simultaneously. On top of that, the confusion is being fanned out on blogs rather than through official testimonies from Microsoft. Developers are now stuck doing a ton of research with the hopes that one of these patterns will lead to "best practices" for the future.</p>
<p>I've listed out the three ASP.NET development approaches I've recently encountered.</p>
<ul>
<li>Codebehind development - this is the 2.x and 1.1x ASP.NET development model. Essentially the events and the business logic are stored in the code-behind. A lot of developers using ASP.NET still develop using this approach since the pre-compiled user controls lend themselves to direct data binding.</li>
<li>Patterns &#38; Practices MVP - The Microsoft Patterns &#38; Practices group have been development application blocks, essentially, these are high-level development libraries that encourage developers to invest more time writing business-specific code. The application blocks that I've found particular cool are Validation, Logging and Exception Handling. This same group has been pushing "guidance packages", a bunch of recipes that facilitate a module-based development paradigm.</li>
<li>MVC ASP.NET - Scott Guthrie, lead developer on the original ASP.NET architecture has been pushing for an MVC framework that closely resembles Zend and Rails. </li>
</ul>
<p>Interestingly enough, the last two pattern approaches infringe on a lot of independent development. </p>
<p>In terms of a working MVC approach, Castleproject's Monorails has been a working implementation with a strong community for some time. However, now that Microsoft has decided to re-engineer this pattern, only time will tell if the Monorails community will be forced into jumping ship; a sad reality that developers in that community have been frequently faced with.</p>
<p><a href="http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx" title="http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx">Phil Haack (Blog)</a>, <a href="http://msdn.microsoft.com/msdnmag/issues/06/08/DesignPatterns/default.aspx">Jean-Paul S. Boodhoo (MSDN magazine 2006)</a>, <a href="http://davidhayden.com/blog/dave/archive/2007/01/16/WebClientSoftwareFactoryIntro.aspx" title="http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx">David Hayden (Blog)</a> and <a href="http://www.codeproject.com/KB/architecture/ModelViewPresenter.aspx" title="http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx">Billy McCafferty (Codeproject)</a> have all offered up sample projects around the MVP paradigm. While all of them are absolutely fascinating to the nerdy developer, they all quietly omit validation and how it affects how events fire on a page.  </p>
<p>The MVP pattern, while being an evolution on MVC, seems to shine when unit testing is at the core of the development approach. Furthermore, because of the event-driven model, the presenter seems like a logical place to begin development. Mocking frameworks like NMock and Ayende's RhinoMock facilitate the isolation of a real persistence layer from DTO's (Data Transfer Objects) being pushed up from a Repository.</p>
<p>Microsoft seems to have missed the boat in the Patterns and Practices group for three reasons:</p>
<ul>
<li>The PnP tests that come with the sample projects incorporate methods that encourage the instantiation of a full-stack web server. This approach fundamentally breaks the notion of a Separation of Concerns since the presenter should be fully working without a web server. </li>
<li>MVP really shines when TDD is applied to the development of the Domain, however with the recipes in place, a developer is more likely to start with a recipe and flush out code for the Presenter directly, essentially falling back on a waterfall development approach.</li>
<li>The MVP sample circumvents the ugly fact that user controls have become too intelligent. Web Controls in ASP.NET implement appearance, events, data and validation. Luckily in ASP.NET 2.0, appearance has been isolated through the use of Skins, however events, data and validation are still managed in a similar manner. MVP, as I understand it, dictates that events are managed by the presenter, however the MVP sample projects attempt to hide the uglyness of the high-level data binding in <strong>Controllers</strong>! How could the terminology for these patterns become anymore confusing?</li>
</ul>
<p><strong>Welcome ASP.NET MVC</strong></p>
<p>What appears to be a Microsoft implementation of Zend / Rails seems to have missed out on the issues that lie dormant in the MVC pattern that MVP has attempted to address.</p>
<p>Where does validation go?<br />
Validation is a terrible word. It refers to data integrity at the persistence level, it refers to user submissions, security contexts and sometimes it's confused with business rules. All of these are different concerns that a web application has to deal with and to be honest, I haven't found a pattern that even attempts to handle all these different aspects of validation in a coherent, systematic and discrete manner.</p>
<p>How are business rules delegated?<br />
Business rules belong in the domain of an application. The issue here is that business rules, being specific to a business, don't really fit into the typical "lets make a blog application in 10 minutes" approach to development. They are crafted in an iterative manner through discussions with the client, and as such, they also tend to disappear from any sample patterns or applications I've come across.</p>
<p>How should you handle AJAX calls to a controller?<br />
My own thinking here is that a presenter architecture shouldn't care whether the event fired is from an AJAX request or a POSTback on a form. The IView should be passed in with the event firing and so the modifications that the presenter handles can be localized to the interface it receives.</p>
<p>I find it particular curious that the developers in PnP have decided to omit their own implementation of the Entlib Validation Framework in their MVP project. Ultimately, I think that Fowler might have been onto something when he said that <a href="http://martinfowler.com/eaaDev/ModelViewPresenter.html">MVP should be split into two separate patterns</a>, Supervising Controller and Passive View.</p>
<p>Technology aside, I think Derek Greer has put together <a href="http://ctrl-shift-b.blogspot.com/2007/08/interactive-application-architecture.html">a fantastic history of MVP and MVC that's worth looking at</a>, regardless of which technologies you're advocating and which patterns you've been committed to implementing.</p>
<p>If anyone out there has answers to these questions, I've been searching hard to come up with a good implementation of these concepts, regardless of economic interest. </p>
]]></content:encoded>
			<wfw:commentRss>http://lebensold.net/development/mvp-or-mvc-or-neither/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
