Export (0) Print
Expand All

Referencing Enterprise Library Assemblies

Before you can build applications that incorporate the Enterprise Library application blocks, you must add references to the application block assemblies and to the Common and Unity assemblies. This prepares your application to use the Enterprise Library. Take care to select the assemblies that reflect your decision to use the Microsoft strong-named assemblies, or the non-strong-named assemblies, or a customized set of Enterprise Library assemblies.

To prepare your application

  1. Add a reference to the application block assembly. In Visual Studio, right-click your project node in Solution Explorer, and then click Add Reference. Click the Browse tab, and then find the location of the application block assembly (the script CopyAssemblies.bat copies all application block assemblies to the bin subdirectory). Select the assembly, and then click OK to add the reference. For example, to reference the Logging Application Block assembly, browse to the bin subdirectory, select the assembly Microsoft.Practices.EnterpriseLibrary.Logging.dll, and then click OK.
  2. Use the same procedure to set a reference to the following assemblies:
    • Microsoft.Practices.EnterpriseLibrary.Common.dll
    • Microsoft.Practices.ServiceLocation.dll
    • Microsoft.Practices.Unity.dll
    • Microsoft.Practices.Unity.Interception.dll.

Ff664629.note(en-us,PandP.50).gifNote:
You will also need the assembly Microsoft.Practices.Unity.Configuration.dll if you wish to reference specific Unity configuration classes in your code. However, in the majority of cases, you will not require this assembly.

All application blocks adhere to the same convention for namespaces. All code for the Enterprise Library is contained under the root namespace, Microsoft.Practices.EnterpriseLibrary. To use elements from an application block without fully qualifying the element reference, add using statements (C#) or Imports statements (Visual Basic® .NET) to the top of your source code file.


Ff664629.note(en-us,PandP.50).gifNote:
For Visual Basic projects, you can also use the references page of the project designer to manage references and imported namespaces. To access the references page, select a project node in Solution Explorer. On the Project menu, click Properties. When the Project Designer appears, click the Reference tab.


Each application block is contained in its own namespace under the Microsoft.Practices.EnterpriseLibrary root. For example, the Security Application Block uses the Microsoft.Practices.EnterpriseLibrary.Security namespace. Complex application blocks may include sub-namespaces, but only if this is necessary to improve readability. For example, the SQL Server portion of the Data Access Application Block uses the Microsoft.Practices.EnterpriseLibrary.Data.Sql namespace.

For example, to use elements from the different namespaces within the Logging Application Block assemblies without fully qualifying the element reference (depending on the features of the block you are using), add the following using statements (C#) or Imports statements (Visual Basic) to the top of your source code file.

using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Logging.Database;
using Microsoft.Practices.EnterpriseLibrary.Logging.Filters;
using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;

Depending on the approach you choose to instantiate Enterprise Library objects, you should also consider importing the namespaces for the core assemblies. If you choose to use the Unity service locator approach, you should import the following namespaces into your classes:

using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

If you use the more sophisticated approach that allows you to take full advantage of the dependency injection capabilities of Unity, you should also import the following namespaces into your classes:

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using Microsoft.Practices.Unity;

After you add the appropriate references to your project, you can create instances of the objects you require in your application code. For information about creating instances of objects, see Creating and Referencing Enterprise Library Objects.


Show:
© 2015 Microsoft