Reusability defined by Microsoft Enterprise Library


Reusability defined by Microsoft Enterprise Library

Wikipedia says “The Microsoft Enterprise Library is a set of tools and programming libraries for the Microsoft .NET Framework. It provides an API to facilitate proven practices in core areas of programming including data access, security, logging, exception handling and others.”

Above definition is somewhat high level so I pitched in with my thoughts.

  1. These are code blocks which are dedicated to perform some individual functions.
  2. These are code blocks which are common in projects independent of the type of project.
  3. These are code blocks which are prepared by Microsoft so can be entrusted with efficiency,industry standards,security, reliability and compliance.

With all the points in mind, a projects can be entrusted with reduced development costs and efforts. For example, the Data Access Application Block provides access to the most frequently used features of ADO.NET, exposing them through easily used classes.

We have following application blocks in Microsoft Enterprise Library 5.0.

  • Caching Application Block – allows developers to incorporate a local cache in their applications. Pluggable cache providers and persistent backing stores are supported.
  • Data Access Application Block –  allows developers to incorporate standard database functionality in their applications.
  • Cryptography Application Block – allows developers to include encryption and hashing functionality in their applications.
  • Exception Handling Application Block – allows developers and policy makers to create a consistent strategy for processing exceptions that occur throughout the architectural layers of enterprise applications.
  • Logging  Application Block – allows developers to incorporate standard logging and instrumentation functionality in their applications.
  • Unity Application Block- used as a lightweight and extensible dependency injection container with support for constructor, property, and method call injection, as well as instance and type interception.
  • Security Application Block – allows developers to incorporate security functionality in their applications. Applications can use the application block in a variety of situations, such as authenticating and authorizing users against a database, retrieving role and profile information, and caching user profile information.
  • Validation Application Block- to create validation rules for business objects that can be used across different layers of their applications.

Before using Enterprise Library, Please follow the minimum requirement mentioned below.

  • Microsoft Visual Studio 2008
  • Microsoft Enterprise Library 4.1 [Now we have 5.0 available and 6.0 in progress]

Now follow these steps

  1. Reference and Deploy : There is no need to include all the dlls, just check the requirements and include only the common dlls, plus the specialized one as per the requirements. Either, Add a reference the precompiled signed assemblies or install them in the global assembly cache (GAC) or just copy them into your application’s bin folder.
  2. Configuration: Now is the time to change the configuration file. To do that, we can use the configuration tools and add the required blocks or another option is to configure them programmatically. For example, connection string, target for logging, policies etc..
  3. Code: Finally we have all the objects from the dlls available for use. For example, the Logging Application Block provides a LogWriter object that makes it easy to create and write log entries to a wide variety of targets.

Example: Working with the Logging Application Block

Add a reference to Logging Application Block


Config Options:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<add databaseInstanceName="LoggingDatabase" writeLogStoredProcName="WriteLog"
addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="DatabaseLogger" />
<add switchValue="All" name="ExceptionLog">
<add name="DatabaseLogger" />

Code: Logger and LogEntry are EntLib objects.

public static void HandleLog(string strLogTitle, string strLogDetails)
<strong>LogEntry</strong> logEntry = new LogEntry();
logEntry.TimeStamp = System.DateTime.Now;
logEntry.Message = strLogDetails;
logEntry.Title = strLogTitle;
logEntry.Severity = TraceEventType.Error;


What’s New in Microsoft Enterprise Library 5.0

We have included the updates available in the most recent version Microsoft Enterprise Library 5.0 from this link:

There are no new blocks; instead the team focused on making the existing blocks shine, on testability, maintainability and learnability. The new features include:

  • Major architectural refactoring that provides improved testability and maintainability through full support of the dependency injection style of development
  • Dependency injection container independence (Unity ships with Enterprise Library, but you can replace Unity with a container of your choice)
  • Programmatic configuration support, including a fluent configuration interface and an XSD schema to enable IntelliSense
  • Redesign of the configuration tool to provide:
    • A more usable and intuitive look and feel
    • Extensibility improvements through meta-data driven configuration visualizations that replace the requirement to write design time code
    • A wizard framework that can help to simplify complex configuration tasks
  • Data accessors for more intuitive processing of data query results
  • Asynchronous data access support
  • Honoring validation attributes between Validation Application Block attributes and DataAnnotations
  • Integration with Windows Presentation Foundation (WPF) validation mechanisms
  • Support for complex configuration scenarios, including additive merge from multiple configuration sources and hierarchical merge
  • Optimized cache scavenging
  • Better performance when logging
  • Support for the .NET 4.0 Framework and integration with Microsoft Visual Studio 2010
  • Improvements to Unity
  • A reduction of the number of assemblies

Vision of Enterprise Library 6.0

Here’s the formal vision for Microsoft Enterprise Library 6.0:

For developers, solution architects, DevOps and IT Pros building, extending and maintaining LOB systems on Microsoft platforms (.NET Framework 4.5 and Windows Azure), Microsoft Enterprise Library 6.0 will provide guidance and reusable components designed to encapsulate recommended practices for end-to-end application development in .NET which facilitate ease of use, consistency, and extensibility.


This is an overview of Enterprise Library and how the use of it is making developer’s life easy.

Author: hershey

A passion for knowledge drives me to do programming, A passion for programming drives me to create something different, A passion for creation drives me to spread the knowledge.

Share This Post On


  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

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

More from CodeSpread:

  • Agile Encounters UnpredictabilityAgile Encounters UnpredictabilityWhat is Agile? Wikipedia says “Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through...
  • WCF Part 2: Fundamentals.WCF Part 2: Fundamentals.We have seen the evolution of WCF in our previous article: WCF Part 1: Why WCF?. Next, we will go through the fundamentals of WCF. I will try to make it more worthy than an interview question puff....
  • Tip : Code Structure C#Tip : Code Structure C#As a developer, I always stress on developing a habit of following the best practices to structure the code. It helps me to easily navigate through the code and also saves a lot of effort in search...
  • Scrum is AgileScrum is AgileIn our last article,Agile Part 1, we have explained basics of Agile and now we are sharing an article on SCRUM What is SCRUM? Wikipedia says “Scrum is an iterative and incremental agile software ...
  • New SDLC: Security Development Life CycleNew SDLC: Security Development Life CycleWhen I heard Security Development Life Cycle, my first reaction was, is it really possible? But, as always, Microsoft surprised me with the introduction of SDL. I just went through a paper publi...
  • Concepts: S O L I DConcepts: S O L I DSOLID - Object oriented programming principles. May be its easy to forget these principles  but for creating a reusable code or maintainable code, people will always have to come back and check ...
  • Split the Web.ConfigSplit the Web.ConfigWhen we work on web projects, we usually encounter with web.config files, not one but may be many at the same time. These web.config files are ASP.NET configuration files. They can be distributed t...
  • POSTMan is required.POSTMan is required.Though it looks like a job posting but in developer’s world, it is a useful tool available as a chrome extension. When my friend referred it, I tried it and liked it so I recommend it every other d...