Configuring the Resource Application Block

The Resource Application Block uses the Enterprise Library Configuration Console to manage its configurable settings.

Adding the Resource Application Block

Once you have opened your configuration file, or created a new one, in the Enterprise Library Configuration Console, the Resource Application Block appears as one of the available block types in the context menu for the Application Configuration node under the New menu option:

Adding the Resource Application Block

Having selected the Resource Application Block the console should appear like this:

The Console with the Resource Application Block added

Notice that the Resource Application Block supports the partial trust permissions interface and configuration settings encryption. In addition, a resource manager has been added and automatically selected as the default resource manager. This will be the resource manager used if no "instance name" is supplied when getting a resource manager.

Adding a Resource Manager

Once you have the Resource Application Block added you will find that a Resource Manager has already been added for you that you can use and rename if you wish to. If you are only going to use one resource manager in your application you can leave everything exactly as it is as this will be the default resource manager. If you want additional resource managers then select New from the Resource Managers node context menu.

Adding a new Resource Manager

The newly added resource manager will be assigned the name Resource Manager automatically, or if that name exists then a sequence number will be added e.g. Resource Manager1. This name is important as it becomes the resource manager instance name. This is the name you must give to the ResourceFactory.GetResourceManager("instance name") method to get that particular resource manager.
Note1: when using the Web Resource Provider for local resources the names you give to your resource managers is critical as they must match the name of the web page or control. If you wish to rename this resource manager then you simply change the name from the properties.
Note2: new to v4.1 is support for custom resource managers.

Renaming The Resource Manager

Once you have more than one resource manager you can select a default resource manager from the context menu for the Resource Application Block node. This will be the resource manager used if no instance name is supplied when getting a resource manager.

Selecting a default Resource Manager

Adding a Resource Provider

You need to assign a resource provider to each resource manager. You can have as many resource managers as you like but you can only have one resource provider for each resource manager. So, if you needed to get resources from two separate sources you would need to configure two resource managers and assign an appropriate resource provider to each one.

Adding a new Resource Provider

As you will see you have a choice of 5 providers.

Adding an Assembly Resource Provider

An Assembly Resource Provider deals with assembly embedded resources. If you selected an Assembly Resource Provider you are asked for a ResourceName

The Assembly Resource Provider

You will not be able to simply type the resource name in as these things can be quite complex, instead you click on the elipsis button to get the Resource Selector dialog.

The Resource Selector dialog

By default the resource selector editor will display all assemblies currently in memory that have embedded resources in compressed form so that you can scroll to locate your assembly quickly. To see the resources in an assembly you can click on the plus symbol and to see all resources click on the Expand button.

The Resource Selector dialog expanded

If your assembly is not in the list then you will need to load it by pressing the Load Assembly from File... button

Loading an Assembly

Once you select your assembly and return to the Configuration Console you will see the resource name has been entered, if you expand the property you will see that the resource name is made up of an assembly name and a base name. You can see now why you did not want to be typing in these names by hand!

An Assembly Resource Provider resource name

Adding a Binary Resource Provider

A Binary Resource Provider deals with resources directly from .resources binary resource files. If you selected a Binary Resource Provider you are asked for a ResourceName but this time it is taken from a .resources file name.

The Binary Resource Provider

Again you will not be able to simply type the resource name, instead you click on the elipsis button to get the Open File dialog filtered for .resources files.

The Open File dialog for Binary Resources

Once you select your file and return to the Configuration Console you will see the resource name has been entered, if you expand the property you will see that the resource name is made up of a base name and a path name. Note: that the basename is the name of the file without its extension.

A Binary Resource Provider resource name

Adding an Xml Resource Provider

An Xml Resource Provider deals with resources directly from .resx xml resource files. If you selected an Xml Resource Provider you are asked for a ResourceName which is taken from a .resx file name.

The Xml Resource Provider

Again you will not be able to simply type the resource name, instead you click on the elipsis button to get the Open File dialog filtered for .resx files.

The Open File dialog for Xml Resources

Once you select your file and return to the Configuration Console you will see the resource name has been entered, if you expand the property you will see that the resource name is made up of a base name and a path name in the same way as for binary resources. Note: that the basename is the name of the file without its extension.

An Xml Resource Provider resource name

Adding a Data Resource Provider

A Data Resource Provider deals with resources from a database configured using the Data Access Application Block. If you selected a Data Resource Provider you are first asked for a database instance name, this will be any one of your configured connection strings. Note: that the Data Access Application Block is automatically configured if not done so already.

The Data Resource Provider

The next property is the ResourceBaseName. This time you simply edit the name. This name relates to a base name used in your database to segregate a set of resources.

A Data Resource Provider resource base name

Adding a Custom Resource Provider

A Custom Resource Provider deals with resources from a source that is not currently supported. This is where you can extend the Resource Application Block with your own resource providers and configure them within your applications. If you selected a Custom Resource Provider you are asked for two properties. The Attributes collection and provider Type name are well documented in the Enterprise Library help documentation but essentially the type is the type name of your custom provider and the attributes collection is a set of parameters that get passed to your provider. Typically one attribute would be set up to collect the resource BaseName.

The Custom Resource Provider

Saving and Validating the Resource Application Block

When you save your configuration a number of validation checks are performed. Typical checks include:
  • The Resource Block must have at least one manager
  • A default resource manager must be selected
  • A Resource Manager must have a Resource Provider
  • A Provider must have a base name
  • Providers may have other mandatory properties like a file path name for Binary and Xml resource providers a type name for a Custom resource provider etc.
All validation messages appear in the grid at the bottom of the Console window

Saving and Validating the Resource Application Block

Last edited Dec 17, 2009 at 1:50 AM by ewdev, version 4

Comments

supradip Sep 8, 2010 at 11:30 AM 
InstallServices.bat doesn't working in my machine. It is failing for first Common Application Block and gives following error. Even I run with administrative right it is not working and same error occuring. What is the reason....
My Enterprise library version is 5.0

eginning the Install phase of the installation.
See the contents of the log file for the E:\Patterns\entlibcontrib2010-01-bin\entlibcontrib2010-01\bin\EntLibContrib.Common.dll assembly's progress.
The file is located at E:\Patterns\entlibcontrib2010-01-bin\entlibcontrib2010-01\bin\EntLibContrib.Common.InstallLog.

An exception occurred during the Install phase.
System.InvalidOperationException: Unable to get installer types in the E:\Patterns\entlibcontrib2010-01-bin\entlibcontrib2010-01\bin\EntLibContrib.Common.dll assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..

The Rollback phase of the installation is beginning.
See the contents of the log file for the E:\Patterns\entlibcontrib2010-01-bin\entlibcontrib2010-01\bin\EntLibContrib.Common.dll assembly's progress.
The file is located at E:\Patterns\entlibcontrib2010-01-bin\entlibcontrib2010-01\bin\EntLibContrib.Common.InstallLog.
An exception occurred during the Rollback phase of the System.Configuration.Install.AssemblyInstaller installer.
System.InvalidOperationException: Unable to get installer types in the E:\Patterns\entlibcontrib2010-01-bin\entlibcontrib2010-01\bin\EntLibContrib.Common.dll assembly.
The inner exception System.Reflection.ReflectionTypeLoadException was thrown with the following error message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..
An exception occurred during the Rollback phase of the installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.

The Rollback phase completed successfully.

The transacted install has completed.