Get started with the Microsoft application blocks

The Microsoft Patterns & Practices group offers chunks of reusable code for developers who are working with .NET languages. Here's a look at the eight application blocks and how you can use them in your next application.

By Mike Gunderloy

Most consultants understand instinctively that time is money: The less time it takes you to deliver a tested, working, complete solution, the higher your hourly rate. One of the keys to better productivity is code reuse. If you have previously tested code that fits the current project’s requirements, you can drop it in to the new application and go on to the next task.

But there’s no reason to limit code reuse to code that you’ve written yourself. There is a tremendous amount of code available on the Internet that you can use. Beware of quality control, of course; downloaded code varies widely in quality. If you’re working in one of the core .NET languages, though, there’s a high-quality repository of reusable code available: the Microsoft Patterns and Practices group. Here’s a look at some of the goodies that this group can provide for your .NET projects.

Patterns and practices
During the last decade, Microsoft realized that it wasn’t enough to just ship development products and then let the rest of us figure out what to do with them. Today’s development environments and client requirements are so complex that it can take years to learn how to write excellent applications. And today’s help files, though comprehensive, can be overwhelming. (Just reading about all of the classes and members in the .NET Framework Class Library [FCL] can take months.)

That’s where the Patterns & Practices group comes into play. Available through the Microsoft Patterns & Practices Web site, the patterns and practices are a series of tested and proven recommendations from Microsoft for use in real-world development. You’ll find four types of information on the site:
  1. Patterns that address specific architecture, design, and implementation problems (You can think of these as structured solutions that show you how to do things.)
  2. Reference architectures that help you plan server deployments, networks, and other parts of your infrastructure
  3. Lifecycle practices that address such issues as trouble-free deployment and operational monitoring
  4. Reference building blocks and services that provide you with reusable code that you can drop into your own solution

Of particular interest to the .NET developer are the series of application blocks that you’ll find in the last of these categories.

Application blocks
The application blocks are chunks of reusable code (and documentation) to meet common requirements. Eight application blocks are available:

What’s in an Application Block?
To get a sense of what the application blocks can do for you, I’ll dig into one of them a bit deeper. Downloading the Aggregation application block gives you a single Windows Installer (MSI) file. Run this file to install the application block on your development computer. Here’s what you’ll get:
  • Source code (in both C# and VB.NET) for the Aggregation application block itself
  • QuickStart samples (in both C# and VB.NET)
  • Documentation in the form of an HTML Help file

The first thing to note is that the application block is supplied as source code rather than as a compiled library. This serves two purposes. First, you can browse through the code and use it for learning, whether you’re more comfortable in C# or in VB.NET. The code in the application blocks tends to be well-structured and well-commented; it seems that there is an internal review process at Microsoft that precedes release.

Second, with shipping source (in Visual Studio .NET 2002 projects), Microsoft offers you the most flexibility in using the code. You can upgrade it to VS.NET 2003, incorporate pieces directly into your own solutions, sign the code so you can deploy it to the GAC, or just compile it as-is and use it as a private library.

The rest of the package ensures that you’re not limited to the source code for the application block when you want to learn what it does. For starters, there’s the QuickStart sample code, which is designed to show the application block in a realistic setting.

For example, the sample for the Aggregation application block shows how to use it in conjunction with the Exception Management application block, the Asynchronous application block, and the Caching application block. Even more useful in many cases is the documentation. As shown in Figure A, this is much more than just a reference to the classes in the application block. The documentation also includes design justifications and architectural notes to help you understand how the application block works and what it’s good for.

Figure A
Documentation for the Aggregation application block

Next steps
Now that you know about the application blocks, what’s next? As a consultant, your career is your own responsibility. You need to set aside time to learn new things. At a minimum, follow the links in this story back to the application blocks and look over their documentation so that you have an idea of what each one is good for. That’s the best way to get them on your radar so that you’ll remember them when you actually need them.

If you can spare a bit more time, download a few of the ones that seem most applicable to your own work and investigate the code. Finally, if at all possible, set aside half a day or a day to browse around the patterns and practices site. If you’re doing serious work with .NET, you’re likely to find other documents and pointers that will save you time with your next project. And that’s the best way to translate your own time into more money in your pocket.

Editor's Picks