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:

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

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.

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.

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

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

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.

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

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

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.

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

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.

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