Selling the Declarative Model
By Jonathan Goodyear
More than two years ago, I dedicated this column to the notion that the next generation of Web application development would be much more declarative than it was at the time (see Declaratively Speaking). By declarative, I meant that large portions of your application would be created by adding specialized server control tags that you customize with attributes to make them behave as desired. Custom code would only need to be applied to implement the validations and business logic that were specific to your particular application. Boy, was I right and in a big way!
Jump ahead to November 7th, 2005 and the official release of Visual Studio 2005. This newest incarnation of the Visual Studio.NET line of software development tools is the most in-depth foray into the declarative programming model that has ever been attempted. I had the pleasure and privilege of speaking at the Visual Studio Launch Event in Orlando on December 8th, 2005 with a good friend of mine, Kirk Allen Evans (who also happens to be a Developer Evangelist for Microsoft). The title of our presentation was Building Cutting-Edge Web Solutions with Visual Studio 2005 and ASP.NET 2.0. The primary focus of the talk was to convince the 2,000+ developers in the audience to set aside their previous conceptions about wizards and declarative programming, and view some of the new tools and techniques available to them with an open mind.
The key to the declarative model in ASP.NET 2.0, which is enabled by Visual Studio 2005, is the concept of the provider model. You may recall that earlier this year I discussed two different models for the creation of a Service Oriented Architecture (SOA): Consumer and Provider (see Consumer vs. Provider). The Provider Model has been used extensively in ASP.NET 2.0 to enable Microsoft to provide a rich set of out-of-the-box plumbing functionality for things such as Membership, Roles, Caching, and Profiles, as well as Site Navigation things that are common to almost all Web applications. The model works because Microsoft separated all of these features into three tiers: controls, APIs, and providers. This way, even if you need to customize the data provider tier to meet the needs of your particular data source (by either creating a new one or inheriting from an existing one), you don t have to touch the API layer or the control layer. The result is that you can almost always use the built-in controls provided by Microsoft, which means that you have to write far less code. It also means that more rich functionality can be put into the controls themselves, so things like selecting, editing, sorting, and paging happen with little or no extra code on your part.
Microsoft s internal tests indicate that the amount of code you have to write using the declarative model could be reduced by as much as 70%. I have to admit, I was skeptical the first time I was presented with those numbers. However, my company has been using Visual Studio 2005 on enterprise applications for nearly a year now, and the amount of code that we now have to write to build Web application functionality has easily been cut in half. Of particular interest to us were the new Data Source controls. These allow you to declaratively connect the visual controls on your ASP.NET pages to the data that they are to display. In the past, this approach led to hard-coded database connection strings and restricted you to a two-tier architecture. ASP.NET 2.0 has an ObjectDataSource control, though, that allows you to bind your visual controls to object collections that implement the IEnumerable interface (see Sorting Objectively online at http://www.code-magazine.com/Article.aspx?quickid=0501021).
If you decide to implement a two-tier architecture after all, the SqlDataSource control will automatically place your database connection string in the connectionStrings section of the web.config file, so you re still following coding standards. No matter what Data Source control you use, though, data caching can now be set declaratively. That includes SQL Cache Dependencies (also known as CacheSync), which allow you to couple cached items to database entities. Lastly, the Data Source controls can leverage stored procedures and accept input parameters from a number of different sources, such as the query string, Session state, and even other controls on the page.
Microsoft has really worked hard to dispel all of the problems associated with previous attempts at declarative programming. Most of the new visual controls are template driven, so their look is highly customizable via simple attributes. Dynamic compilation allows the strongly-typed Profile object to be custom-defined in the web.config file using XML. DataSet objects can be defined using a wizard that generates XML that can immediately be accessed with IntelliSense. The list goes on and on.
Although it is perfectly acceptable for you to merrily keep doing things the same way that you did with Visual Studio.NET 2003, I urge you to actually give the declarative model of development a try. I think that you ll be quite surprised at your increased productivity.
Jonathan Goodyear is president of ASPSoft (http://www.aspsoft.com), an Internet consulting firm based in Orlando, FL. Jonathan is Microsoft Regional Director for Florida, a Microsoft Certified Solution Developer (MCSD), and author of Debugging ASP.NET (New Riders). Jonathan also is a contributing editor for asp.netPRO. E-mail him at mailto:[email protected] or through his angryCoder eZine at http://www.angryCoder.com.