views:

175

answers:

2

i.e. Is MVP still the next best choice when MVC is not an option?

I thought I'd ask this here as I'm sure there are others like me who don't have the luxury of being on a green-field project and want to refactor a webforms UI to better separation of presentation from business objects...

I'm working on a legacy application tasked with adding relatively small additional requirements, enhancements, and bug fixes.

The part of the application I'm addressing here may be characterised as the UI for a set of CRUD operations over business objects that are persisted to a relational database.

The existing UI uses a MultiView control to navigate between the editing of associated business objects (one-one associations or one-many / parent-child). Yes, that's right - all on one page. Unfortunately there is very sparing use of UserControls so the markup and code-behind is hundreds of lines long.

On each View a FormView manages the CRUD over the business objects via various ObjectDataSources. Within the ItemTemplate of each FormView various server controls databind to fields or methods on an ObjectDataSource.

I'd like to introduce more separation of concerns and get some of the reams of code out of Page code-behind.

My research so far suggests to me that I might consider:

  1. Use a flavour of Model View Presenter; more specifically - use an ObjectContainerDataSource from the Web Client Software Factory to make it easier to bridge between the current UI and a set of new Presenter classes.

  2. Build again from scratch with an MVC framework (not an option).

  3. Leave well alone; an MVP pattern is only justified if I need to re-use my Presentation in different UI scenarios?

If I settle with (3) I'd still like to know how to start refactoring towards better separation of presentation.

What would you do? any other ideas gratefully received...


Here's some more background for anyone who's interested:

The domain is in pharmaceutical research but that's fairly irrelevant and you can think of it as pretty typical line-of-business - user configuration of a family of settings that form the operating conditions of another part of the application.

The business object layer has already been built in a very consistent manner. Although I may not like it, I can't neccesarily justify changing it. Each object is it's own Repository / Data Access Object in that there are static methods for 'get by ID' and 'get list by criterion'. Where possible common operations are implemented in an abstract base class. Each business object delegates the data access work to a Data Access Layer that makes use of ADO.NET 2.0 Provider Factory mechanisms to remain relatively abstracted from a concrete Provider. In this respect it shares a lot in common with any app that uses the Data Access Application Block from the Microsoft Enterprise Library.

There are fairly exhaustive integration tests written in NUnit that set up a test database from scratch so they take ages to run but at least they verify that stuff works as it should (at some point in the past anyway ;-). There is almost no true unit testing in place (yet).

+1  A: 

http://haacked.com/archive/2006/08/09/ASP.NETSupervisingControllerModelViewPresenterFromSchematicToUnitTestsToCode.aspx has a good example of doing MVP with webforms. The advantage is not just that your UI is decoupled from BL - the real treat is that you can write tests for the code.

mcintyre321
+2  A: 

WebForms now has an emerging effort in the form of the ASP.NET Web Forms MVP project

"...there are still a host of compelling advantages to ASP.NET Web Forms.

The ASP.NET Web Forms MVP project is ... an approach that facilitates separation of concerns and testability whilst maintaining the rapid development that Web Forms was built to deliver"

Rob Conery has concerns that this may be a wasted effort and an unneccesary distraction now that we have MVC but at this stage I still think the source code is worth a look...

rohancragg