Wednesday, April 02, 2008

ASP.NET MVC Framework - First Look

I have been playing with the ASP.NET MVC Framework (Preview 2) recently. For those of you who don't know what the MVC framework is about, then read the overview docs in the link above. (I'll wait).

Issues with ASP.NET
While the ASP.NET framework is a huge improvement over classic ASP, it does have some pitfalls and downsides. The Postback and Viewstate pattern does add flexibility, it does also add bloat in the form of encrypted values to your page. This means slower download times and ugly HTML (Some designers really, really hate this. Good synopsis of Viewstate issues and work arounds Here

While ASP.NET goes some way into code seperation, by splitting the View from the Code, the Page_Load mechanism can promote lazy developers into stuffing alot of business logic into there.

Also the current model makes unit testing ASp.NET pages difficult.

There are alternative patterns already being used. The current project I am working on uses the Model View Presenter pattern. MVP adds more seperation from standard ASP.NET and allows for greater testability. I quite like MVP and is probably better suited to larger projects, due to extra initial coding. I will do a follow up post on my experiences with MVP, but there are quite a few resources available for a quick grok.

While I like the MVP pattern, I would strongly recommend people looking at the MVC pattern also before comitting to the MVP.

Model View Controller
The MVC pattern is quite common in standard GUI apps. Cocoa development on the Mac and iPhone actively promotes and enforces the pattern, and Java developers have been using it for a while. It is only in the last few years that web developers have embraced the technology.

The ASP.NET MVC framework is still in beta, with Preview 2 being released recently. The major benefits I can see are

  • Greater Testability and Mockability

  • Greater seperation of concerns - logically breaking down app into components

  • URL rerouting built in

  • Elimination of PostBack and Viewstate

Along with these it enforces a logical project and solution layout, so going back to old code will be easier under MVC.

I went off on a tangent on what I originally thought I would post about, but I will post some sample code about MVC in the future as I get to grips with it.

1 comment: said...

thank you for nice post