BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Model-View-Presenter for Web Forms

Model-View-Presenter for Web Forms

This item in japanese

While it is possible to use a MVC-style architecture with ASP.NET Web Forms, most find it to be a clumsy match. The rich components and stateful nature of Web Forms simply doesn’t mesh well with the MVC pattern. Yet developers still long for the separation and testability that MVC offers. This is where the open source project Web Forms MVP comes into play.

The principal goal of Web Forms MVP is to offer much of the control that ASP.NET MVC offers while still maintaining the high level of productivity you get from using rich controls. In the simplest case Web Forms MVP simply requires the developer to move their logic out of code-behind files and into presenters.

Web Forms MVP claims to be especially good at composing pages. Rather than having a single page and action controller, Web Forms MVP encourages developers to break up their pages into separate reusable components. Each component is considered to be its own view and has its own matching presenter. Presenters are meant to be small and largely independent, though they can communicate with one another.

This framework was also built with Inversion of Contorl and Dependency Injection in mind. The official release contains integration libraries for Castle and Unity. The companion project, Web Forms MVP Contrib, offers support for Ninject, StructureMap, and Autofac.

Since the bulk of the logic is moved into the presenters you can perform automated tests on them using the same techniques you would use if you were testing controllers or view-models in other frameworks. Much of the underlying framework that makes this possible comes from the System.Web.Abstractions library originally introduced with ASP.NET MVC.

Rate this Article

Adoption
Style

BT