Line of Business Web Apps with Microsoft ASP.Net MVC 2.0
With the delivery of a number of successful line of business applications built with the Microsoft ASP.Net MVC 2.0 architecture we thought it was time to blog about our view of the framework versus traditional web forms. Both the Foundtastic web app for the City of Edmonton Transit department and the DOC-IT/SAMPLE-IT system in use at the Wood Buffalo Environmental Association (WBEA) are excellent examples of custom web solutions leveraging ASP.Net MVC 2.0. In the case of the latter example a multi-million dollar scientific research operation is managed through the powerful DOC-IT/SAMPLE-IT web app. There are 3 significant improvements MVC brings to web app development for Microsoft environments: powerful client-side scripting, performance and testability.
Brief Introduction to Microsoft ASP.Net Model-View-Controller (MVC) 2.0
The Model-View-Controller pattern has been around for over three decades. It has been adapted for use in several user-interface frameworks. It is a very simple pattern that advocates the clear separation of responsibilities between the model (data), controller (logic & orchestration) and the view (presentation). It has been observed to help produce more maintainable, structured applications. Web Forms and ASP.NET MVC differ radically in their adherence to separation of concerns best practices.
jQuery & client-side scripting
In the early days of Web development, client-side script was mostly relegated to tasks such as validation. With the advent of Ajax this changed and a lot of complex JavaScript was written to create AJAX-enabled Web applications. This was tedious, complicated and error-prone work. Client-side scripting has a reputation for being quirky and difficult to get right. IDE support for the JavaScript language was lacking until recently. The language itself, while very capable, was not understood very well. The Document Object Model as implemented by different browsers caused several compatibility issues and generally earned its name as a difficult area to get right.
Over time, frameworks emerged to make this work easier. One such framework that emerged, and has quickly become the de facto standard for authoring client-side functionality, is the jQuery4 framework. jQuery makes it quite easy to work with client-side script. It abstracts away differences between common browser platforms and offers an elegant CSS-like syntax for targeting elements of the DOM. This, coupled with its fluid interface, has made client-side programming a joy.
The Web Forms framework and the ASP.NET MVC framework differ substantially in their ability to work seamlessly with jQuery.
Performance
The ASP.NET MVC Framework allows for very lightweight markup. The application of unobtrusive JavaScript principles also leads to less markup being produced since it avoids repetitive inline markup such as that used for event subscriptions. Any state maintained by an MVC application is targeted and usually a small fraction of ViewState on similar Web Forms pages.
Performance differences are even more pronounced with Ajax applications. With Web Forms, the entire page lifecycle with all its associated traffic/code is required. This leads to much higher traffic back-and-forth with the server.
Testing
Solid and easy testing of business logic and data access is considered to be critical to the development of maintainable Web applications. Web Forms applications are very hard to test. This is primarily due to the following reasons:
• It remains hard to automate Web Forms applications without running them inside a complete hosting environment. It is not possible to easily simulate a complex hosting environment such as IIS.
• The view often contains business logic and presentation, making it very hard to test the business logic without testing the presentation.
In practice this meant that Web Forms applications were usually tested using elaborate UI automation tools or manual testing – an error-prone and expensive process.
ASP.NET MVC makes testing easy alleviating many of Web Forms barriers. All of the core components of ASP.NET MVC are designed to easily run from any unit testing container. Furthermore, the entire MVC application is compiled within the Visual Studio development providing early indication of errors and problems.
I’ll be writing about deploying an MVC web app to the Microsoft Azure platform in an upcoming blog!
References:
Microsoft Developers Network
http://msdn.microsoft.com/en-us/
IEEE – ACM
http://portal.acm.org/citation.cfm?id=1088812