Saturday, June 6, 2009

How to use Enterprise Library using C#

2 comments
Summary

The Microsoft Enterprise Library is a collection of reusable software components (application blocks) designed to assist software developers with common enterprise development cross-cutting concerns (such as logging, validation, data access, exception handling, and many others). Application blocks are a type of guidance; they are provided as source code, test cases, and documentation that can be used "as is," extended, or modified by developers to use on complex, enterprise-level line-of-business development projects.

Some Features

While using enterprise library you have to concern about opening and closing connections.
This will automatically handle connection pooling and other important errors of connection and database.

I had used Enterprise Library 2.0 - January 2006.
To use Enterprise Library you required to add reference of following files:-

  • Microsoft.Practices.EnterpriseLibrary.Common.dll
  • Microsoft.Practices.EnterpriseLibrary.Configuration.Design.dll
  • Microsoft.Practices.EnterpriseLibrary.Data.dll
  • Microsoft.Practices.ObjectBuilder.dll
View code below which I had used to connect one of my tables to master database.

#region Using

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using System.Data.Common;

using Microsoft.Practices.EnterpriseLibrary.Data;

#endregion

public class spt_monitor

{

public DataTable Read()

{

try

{

Database db = DatabaseFactory.CreateDatabase("masterConnection");

DbCommand dbCommand = db.GetSqlStringCommand("Select * from spt_monitor");

DataSet dataSet = db.ExecuteDataSet(dbCommand);

return dataSet.Tables[0];

}

catch

{

return null;

}

}

}

This code is simply loading a dataset without much code.

Download Enterprise Library from following links:-

Download another tool which will generate code for Enterprise Library from crococode.com

http://crococode.com/user/Download.aspx

You can also download code running code which is using master database as example.

http://www.4shared.com/file/110209896/9461588/EnterpriseLibraryDemo.html

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.

2 comments:

Himanshu Raj said...

Thanks for the blog...very good explanation....seems u have a lot in store..!!

Himanshu Raj said...

Very well explained.....We can have a rough idea of enterprise Libray...Lemme try it out....and then I can comment further for any doubts....!!