April 04, 2008

ASP.NET MVC: Building Web Apps without Web Forms

ASP.NET Web Forms made it very easy to get started, but, in other ways, trying to apply my design principles to Web apps was a struggle. Web Forms are relentlessly UI focused; the fundamental atom is the page. You start by designing your UI and dragging controls. It's very seductive to just start slapping your application logic into the page's event handlers (much like Visual Basic® enabled for Windows® apps).

On top of that, unit testing of pages is often difficult. You can't run a Page object through its lifecycle without spinning up all of ASP.NET. While it is possible to test Web apps by sending HTTP requests to a server or automating a browser, that kind of testing is fragile (change one control ID and the test breaks), hard to set up (you have to set up the server on every developer's machine exactly the same way), and slow to run.

As I started building more sophisticated Web apps, the abstractions that Web Forms provides, like controls, view state, and the page lifecycle, started to chafe rather than help. I was spending more and more time configuring data binding (and writing tons of event handlers to get it configured correctly). I had to figure out how to reduce the view state size to get my pages to load faster. Web Forms require that a physical file exist at every URL, something that dynamic sites (like a wiki, for example) make difficult. And successfully writing a custom WebControl is a remarkably complex process that requires a comprehensive understanding of both page lifecycle and the Visual Studio® designer.

Related

Link Posted by Tim at April 4, 2008 10:49 AM | TrackBack