Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Windows

Reusability defined by Microsoft Enterprise Library

0.00/5 (No votes)
12 Feb 2013CPOL4 min read 9.6K  
This is an overview of Enterprise Library and how the use of it is making developer’s life easy.

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.”

The 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 the 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

EntLib

Config Options:

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

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;
<strong>Logger</strong>.Write(logEntry,"ExceptionLog");

}

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: http://msdn.microsoft.com/en-us/library/ff632023.aspx.

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.

Ref: http://blogs.msdn.com/b/agile/archive/2012/11/08/enterprise-library-6-0-vision-scope.aspx

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)