Refactoring techniques for asp.net webforms application

asp.netrefactoring

I'm working on a large application written in asp.net web forms. It was developed under asp.net 1.0, and still uses DataGrid, though portions have been updated.

Most of the code resides in either the codebehind, or in controller classes that can't be instantiated outside of a running IIS. (The controller framework we use provides lifetime management tied to session state.) Data access is through a custom DAL, meaning that most of that code also requires a live database with proper data inside it.

I want to decouple the code from the database and the web server, so that I can run it under a test harness. Are there any good strategies for moving from this sort of code to a more testable structure?

Best Answer

The best way would be to refactor out the code-behind to logical layers (services, DAO/Repository, etc). Look at Model View Presenter for ideas how to abstract away the rest, but realistically an endeavor like this is usually better served by rewriting the thing properly; speaking from experience it's very hard to refactor WebForms when it's done terribly, chances are you will have to redo so much that you're basically rewriting the thing anyways.