Myths about Microsoft Enterprise Library 5.0

It is so long i am hearing about Microsoft enterprise library, initial days we used a part of it called Microsoft Data Access Application Block, or some of us might be familiar with the name SQLHelper class.

It is been there for years and evolved in to a perfect set of application blocks, that helps in enterprise application development. In out multi-tier architecture applications to complex transaction sensitive applications, we can use it any where we needed.

Each framework or tools will have it’s own advantages and disadvantages. The Spring.NET, Castle Project they are all set of consistent blocks helps in building robust, state of the art, reliable and flexible applications.  I am not saying that Enterprise Library replaces Spring.NET, & Castle Project.

If consider Spring.Web Framework  library it provides dependency injection between our ASP.NET webforms, master pages, which web form is dependent to which master page and passing the dependent mater page objec to the page etc. It even provides the Masterpage support for ASP.NET 1.1 applications, you can refer to  Spring.Web Framework – Article – Chapter 22 . I would love  Spring.NET in some cases like AOP(Aspect Oriented Programming), WCF Services and dependency injections for  ASP.NET Web Applications and even data access.  

But as i said earlier, Each framework has it’s own BEST way of doing it.

These frameworks are proven efficient for certain level of business applications, but i am introducing Enterprise Library as a good alternative.  Choosing between all these framework is up to the organization and project need.

What is all this about Enterprise Library 5.0

The Microsoft Enterprise Library is a collection of reusable software components (application blocks) designed to assist software developers with common enterprise development challenges. Application blocks are provided as source code plus documentation that can be used “as is,” extended, or modified by developers to use on complex, enterprise-level line-of-business development projects. (Taken from Code Plex & MSDN).

I am using some of the sections from MSDN – Patterns & Practices to give much more understanding about the Enterprise Library.

Benefits of Enterprise Library

The design of application blocks encapsulates the Microsoft recommended and proven practices for .NET application development. These good practices are demonstrated in the overall design of the Enterprise Library, as well in the context-specific guidelines in the design of individual application blocks and QuickStarts. Software developers can add application blocks to .NET applications quickly and easily. For example, the Data Access Application Block provides access to the most frequently used features of ADO.NET, exposing them through easily used classes. In some cases, application blocks also add related functionality not directly supported by the underlying class libraries.

Goals for Enterprise Library

Enterprise Library is a collection of application blocks intended for use by developers who build complex, enterprise-level applications.

Enterprise Library is used when building applications that are typically to be deployed widely and to interoperate with other applications and systems. In addition, they generally have strict security, reliability, and performance requirements.

The goals of Enterprise Library are the following:

  • Consistency. All Enterprise Library application blocks feature consistent design patterns and implementation approaches.
  • Extensibility. All application blocks include defined extensibility points that allow developers to customize the behavior of the application blocks by adding their own code.
  • Ease of use. Enterprise Library offers numerous usability improvements, including a graphical configuration tool, a simpler installation procedure, and clearer and more complete documentation and samples.
  • Integration. Enterprise Library application blocks are designed to work well together or individually.

Active Releases

Retired Releases

That’s just an introduction, Why so special about it. Every framework or library provides that?.

If i recollect the SQLHelper.cs , it was initially developed for SQL Server.

But the new Data Access Application Blocks(3.x,4.x,5.x) supports Multi Data Source support with some specially designed helper classes just by changing the connection string. This is really helpful if we are not depending on stored procedures and want to keep all data access queries within the application itself.

If we user Dynamic Queries or Text queries it would help us in multi data source, think about you have an SQL Server DB and have stored proceduces to provide data queries and some time later since you have very little user base or data needed to manage in your application., you are deciding to move to an ACCESS DB or MYSQL DB.

It would be difficult for your developers to ReWrite each and everything for supporting ACCESS DB or MYSQL DB. Since normally we used System.Data.SqlClient classes (SqlConnection,SqlCommand, SqlDataAdaptor).

But when you develop an application we have to think about future extensibility and possibility to have multiple data source support with minimal effort. This is where Microsoft Data Access Block comes in handy.

Support currently you have connection string like below, through which you are connection to SQL Server.

[code lang=”xml”]

<add name="DataConnectionString" connectionString="server=(local)sqlexpress;database=Northwind;User ID=nw_user;Password=voila;Application Name=Northwind" providerName="System.Data.SqlClient"/>

[/code]

Infuture if you migrate your DB to MSAccess, you can just change connection string like below and start using your application working with new database. How easy it is?. Cool na.

[code lang=”xml”]

<add name="DataConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; User ID=myuser; Data Source=|DataDirectory|northwind.mdb; Password=" providerName="System.Data.OleDb"/>
[/code]

With minimal effort application start working on with another type of data source. How it happens and should be working like that?.

We are using Microsoft Data Access Application block library.

Add reference to

Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.ServiceLocation.dll – this lib is needed for locating the provider asssembly a light weight service locator
Microsoft.Practices.EnterpriseLibrary.Data.dll

import the following namespaces, in the data access logic class

[code lang=”c-sharp”]
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
[/code]

and here is the code for access the database

[code lang=”c-sharp”]

string DbConnConfigName = "DataConnectionString";
Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>(DbConnConfigName); // a light weight locator

int orderCount = (int)db.ExecuteScalar(
CommandType.Text,
"select * from [Orders]");

string message = string.Format(
"There are {0} Orders",
count.ToString());
Console.WriteLine(message);

[/code]

This is pretty easy right. Since we using a Generic class for data access, Data Access Application block will locate the associated classes to provide data access internally, according to the providerName=”System.Data.OleDb” or providerName=”System.Data.SqlClient” or providerName=”System.Data.OracleClient” we mentioned in the connection strings section.

Similar way EntLib(a Short for Enterprise Libray) provides Policy based exception handling block which is widely used in .NET Enterprise application development. Anotehr useful block is Logging application block which helps us in providing logging based on policy set in our config file. If you want to suppress a certain logging in production environment, you can set up policy to not to log it. cool na.

Enterprise Library contains the following application blocks:

The Caching Application Block. Developers can use this application block to incorporate a local cache in their applications.
The Cryptography Application Block. Developers can use this application block to incorporate hashing and symmetric encryption in their applications.
The Data Access Application Block. Developers can use this application block to incorporate standard database functionality in their applications.
The Exception Handling Application Block. Developers and policy makers can use this application block to create a consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications.
The Logging Application Block. Developers can use this application block to include standard logging functionality in their applications and systems administrators can use the configuration tool to adjust the granularity of logging at run time.
The Policy Injection Application Block. This block contains legacy code for backwards compatibility with existing applications. The new functionality is available by using the Unity interception mechanism and call handlers located in the related application block assemblies.
The Security Application Block. Developers can use this application block to incorporate authorization and security caching functionality in their applications.
The Validation Application Block. Developers can use this application block to create validation rules for business objects that can be used across different layers of their applications.
Unity Dependency Injection and Interception. Developers can use this to implement a lightweight, extensible dependency injection container with support for constructor, property, and method call injection; and to capture calls to target objects and add additional functionality to the object.

You can find lot of resources on EntLib codeplex here , it’s a treasure hunt for a .NET Developer.

My time is limited, so i am stopping about for now. I will write down more on this later some time. I hope you got a basic idea of the things.  I will correct mistakes in this article later. This is just a DRAFT release. Happy Coding Guyz….

You can find Microsoft Enterprise Library – HandsOn Labs  which a nice way to learn for a beginner or experienced. It provides a step by step instruction about how to use and configure each application blocks in your application.

EntLib5 Developer’s Guide – Release Candidate!

Share extensions via EntLibContrib Project

Enterprise Library on Windows Azure

& more and more visit Patterns & Practices – Enterprise Library Home

Discussion Forum

One thought on “Myths about Microsoft Enterprise Library 5.0

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.