Pages

Wednesday, January 16, 2008

Microsoft Application Blocks

Application Blocks are C# and VB.NET classes distributed as Visual Studio projects that can be downloaded from Microsoft's Web site and used in any .NET application, including ASP.NET Web applications. They are useful and powerful tools that can make applications more maintainable, scaleable and efficient. In 2002, Microsoft released two Application Blocks that encapsulate two of the most common programming tasks: data access and exception management. They are:
1.)Data Access Application Block
2.)Exception Management Application Block
These two Application Blocks contain classes, static methods and interfaces that greatly simplify SQL Server data access and application exception management.
The Data Access Block provides static methods located in the SqlHelper class that encapsulate the most common data access tasks performed with Microsoft SQL server.Static method means that the class methods can be called without instantiating an instance of the class.For example, the method ExecuteReader() within the SqlHelper class can be called by simply using the statement SqlHelper.ExecuteReader() -- no object instantiation of the SqlHelper class is required. These static methods can be used to return SqlDataReader, DataSet and XmlReader objects containing database information. You can call stored procedures and SQL commands and specify stored procedure parameter details. The SqlHelper class also supports transactions.
To get started with the Data Access Application Block you must first download the installer at http://download.microsoft.com/download/VisualStudioNET/daabref/RTM/NT5/EN-US/DataAccessApplicationBlock.msi.

The second Application Block encapsulates exception management. The Exception Management block provides a framework enabling you to log exception information, isolate exception code from your business logic and manage exceptions efficiently and consistently. The Exception block also provides excellent base classes and interfaces that can be used to create your own exception management framework or extend the Application Block to met the needs of your particular system. The Exception Management Block can be downloaded at http://download.microsoft.com/download/VisualStudioNET/emabref/RTM/NT5/EN-US/ExceptionManagementApplicationBlock.msi.

The Benefits of Using Application Blocks
Arguably, the biggest benefits to using Application Blocks are faster and more modular development. Because much of the "nuts and bolts" of data access and exception handling is wrapped in the Application Blocks, you don't have to worry about the tedious details required to return a DataReader or write an exception to the System Log. This allows us to concentrate on the business logic in our applications. Application blocks cut down on redundant code and provide a buffer between you and the .NET framework. Additionally, because Application Blocks are distributed as Visual Studio projects, you are free to browse the source code and make changes and/or additions to suit the needs of your own application. Finally, Application Blocks come with very good documentation and quickstart samples to get you up and running quickly.

No comments: