The Rationale Behind ASP.NET MVC

An ASP.NET page is made of server controls with their own object model and logic


April 07, 2008
URL:http://www.drdobbs.com/windows/the-rationale-behind-aspnet-mvc/207002116


In spite of its early Community Technology Preview (CTP) stage, the ASP.NET MVC Framework is extremely popular and is being talked a lot in blogs and community sites. Shipped as part of the ASP.NET 3.5 Extensions toolkit (along with other features such as ASP.NET controls for Silverlight and the ADO.NET Entity Framework), the ASP.NET MVC framework represents an alternative to the classic Web Forms model for ASP.NET pages and applications.

Six years ago, the Web Forms model received a warm welcome from the Web developers' community because it really made it simple to build pages and, more importantly, without requiring JavaScript and HTML strong skills. As a result, ASP.NET brought a number of C and C++ programmers to Web development, thus raising the quality of code and multiplying sites and applications. In a sense, ASP.NET disrupted the de facto association between the pair HTML+script and the Web. It worked just great for a few years.

In the long run, having a number of smarter and smarter developers at work on Web applications using modern and fully object-oriented languages such as C# raises some new issues as far as the design of applications is concerned. ASP.NET Web Forms has a number of benefits, but is not perfect either. In particular, ASP.NET Web Forms is lame on testing and separation of concerns (SoC).

I'm not here to say that SoC or testing is just impossible or impractical in the ASP.NET's Web Forms model. It's only that ASP.NET in conjunction with Visual Studio makes too easy to go the other way. Deadlines are always too close for any developer on the face of the earth; it's tempting to drop handmade controllers and presenters and place logic straight in the code-behind class.

The Web Forms model is centered around the user interface and the page. The ASP.NET page is made of server controls (often, rich controls) with their own object model and logic. An ASP.NET page is the center of the universe -- it's the view for the user, but also the container of most presentation logic, and maybe some business logic too.

Automated testing is hard because it's tough to decouple pages from the ASP.NET runtime and page lifecycle. Testing is not impossible but requires much more work than just preparing the test harness.

Adopting common industry patterns such as MVP and MVC is left to the good will of individual teams and developers. The Web Client Software Factory (WCSF) is just an attempt to provide a framework for SoC and testing; and it came out even too complex than required in most cases.

At the same time, a growing number of smart people in the industry are embracing new paradigms and practices. An example is the ALT.NET community. The ASP.NET MVC framework goes in the direction of providing an alternate model for building ASP.NET applications that is based on a different set of requirements: full SoC and, especially, test-driven development.

As of today, the ASP.NET MVC framework is physically separated from Web Forms and requires a modified runtime to work. It should be noted, though, that the ASP.NET MVC framework is fully extensible and it's only a tech-preview. It is far from being a released product with its own defined physiognomy.

Should you use it for development? No, because there's no Go-Live license and the product is not even in beta. Should you play with it? Yes, if you're just curious about different approaches to the building of Web applications and surely if you feel a bit uncomfortable with ASP.NET postbacks and viewstate.

The ASP.NET MVC framework changes the paradigm according to which you build Web applications. It may be shocking at first, if you're not prepared or don't really feel the need for change.

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.