Why choose ASP.Net MVC instead of ASP.Net Webforms?

If you are doing web development with Microsoft technologies, you are maybe asking yourself about what technology you should be using: the legacy Webforms or the new MVC framework.

The different layers in an ASP.Net Webforms application

WebForms_Archi

I want to solve my problems with automated tests

Webforms has not been released bearing in mind the aim of being simply tested. The first goal was to make the web stateful, but it’s another story :). In fact, ASP.Net webforms creates a quite big difficulty to handle Separation of Concerns (SoC) in your code.

Of course, I can record integration web tests (but you should know this is not enough to have a team with a good productivity (unit testing simplifies maintainability and refactoring of the code)), and that is almost the only solution to test a webform page, with its famous code-behind.

Was ASP.Net MVC created to make possible the untestable logic in code behind?

No. Everyone that wanted to write clean and tested code, could use the MVP pattern (easier to use with webforms than MVC or MVVM). This pattern provides us the ability to abstract the conditional logic in an external class that does not depend on the webforms framework.

The only code that lies in the code behind comprises some properties and a call to the corresponding presenter instance, at Page_Load.

Each event handler (MSDN Event Handler) just behaves as a transfer object towards the presenter instance.

You can find a more detailed description of the MVP Pattern with ASP.Net webforms, here in MSDN Magazine.

On CodePlex, this is a sample of an implementation of MVP with ASP.Net Webforms

The different layers in an ASP.Net MVC Application

MVC_Archi_SoC

How ASP.Net MVC helps you to test your code?

First, the code that we would have placed in the code-behind (for those that did not applied MVP :)) now has its own place: the controller. ASP.Net MVC gives us the ability to design code while keeping separation of concerns and testability in mind.

And it does the difference for the maintainability of every software that would be written this way.

Advertisements

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s