Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News ASP.NET MVC 3 Embraces Dynamic Typing

ASP.NET MVC 3 Embraces Dynamic Typing

This item in japanese

Nearly a decade ago Microsoft gambled big on WebForms and static typing. With the dial cranked all the way over to full encapsulation, each page could almost be treated as its own program. In the intervening years the industry has largely gone in the other direction, favoring separation of concerns over encapsulation and late binding over early binding. This leads us to a two rather interesting questions.

The first is a question of terminology. When you consider the original Smalltalk MVC pattern, the views and controllers are not only tightly coupled but literally come in pairs. This is exactly what you would find in most Microsoft frameworks including classic VB, WinForms, WebForms, WPF, and Silverlight, all of which use a code-behind file for the controller logic. But these days when someone says “MVC” they usually mean a framework wherein the view and controller are very loosely coupled. This is especially true of web frameworks where HTML’s form submission mechanism allows any view to target any controller. Since this article is talking about web technologies, we’ll stick to the modern definition.

The second question is, “If you are Microsoft, how do you switch tracks without up without alienating your developers?” So far their answer has been, “By releasing a new version every year until you get it right.” The first production release of ASP.NET MVC was in March of 2009. March of 2010 saw the release of ASP.NET MVC 2.0. And with the 3.0 in its second release candidate, we should see a production drop by March of next year.

ASP.NET MVC 3.0 Release Candidate 2 was announced on December 10th. RC 2 builds on Microsoft’s commitment to jQuery by including jQuery 1.4.4, jQuery Validation 1.7, and jQuery UI in the default project templates. While they have been toying with moving away from server-side controls for a while, the inclusion of jQuery UI suggests that they are really taking it seriously now.

For those concerned with scalability, there is now much finer control over session state. Using the SessionState attribute, you can indicate to controllers whether session state should be read-only, read-write, or skipped entirely. This won’t matter for single-server websites, but can have offer huge gains when the session state has to be fetched from another server.

MVC 3 will include the Razor view engine. This engine HTML encodes output by default, reducing the likelihood that raw text will find its way on the screen. And even when there isn’t a risk of HTML injection attacks, a bit of unencoded text can easily prevent a page from correctly rendering.

In what will probably be a shock to many C# developers (and elicit snide remarks from the VB crowd), MVC 3 is embracing dynamic typing for controllers and view. The ViewBag property exposes a dynamic object upon which one can add properties at run time. Generally speaking this is used to transmit non-modal data from a controller to a view. The examples provided by Scott Guthrie include status text (e.g. the current time of day) and the items used to populate a list box.

Rate this Article