This project is read-only.

Resource Providers

The Resource Providers job is to deliver to the application a Resource Manager of the appropriate type. All Resource Providers must implement the IResourceProvider interface that specifies a CreateResourceManager() method which returns an ExtendedComponentResourceManager see Managers for details on the ExtendedComponentResourceManager.

Assembly Resource Provider

Most resources are edited in xml files with the extension .resx using a resource editor. These files get compiled into binary resource files with the extension .resources and then embedded into the associated assembly. Visual Studio will do all this automatically for you creating an Xml file with the default name of Resources.resx in the Properties folder. This ends up being embedded into the assembly with a base name made up from your assembly namespace plus Properties.Resources.resources. You are not restricted to a single set of resources embedded into an assembly, however the base name must be unique.

If you are using resources for internationalization then you can place translated resources into separate associated files that includes the culture in the file name. So the french generic translation for Resources.resx would become and Portuguese spoken in Brazil would become These files would be compiled into binary resource files called Resources.resources but placed in subfolders called fr and pt-BR respectively. The final assembly would have the neutral culture file Resources.resources embedded and create Satellite assemblies for the other resources such that if the assembly was called Fred.dll then you would get another two Fred.dll satellite assemblies that contained only the french generic and brazilian portuguese resources sitting in sub folders fr and pt-BR respectively.

The Assembly Resource Provider allows you to configure a Resource Manager for any set of resources held in any assembly so you are not limited to the currently executing assembly and manages the loading of the assembly and the various satellite assemblies in their sub folders in the normal .NET Framework resource fallback fashion.

One trick you can do with the Assembly Resource Provider is to create a single resource only assembly and use it to hold all the resources for your application no matter how many assemblies you have in your application. The big advantage of this is that if assemblies share similar resources they do not need to be stored more than once. The other advantage is that if you are using a translation service you have less resource files to handle and update, of course each time changes are made, these assemblies have to be re-compiled and re-installed.

The unique feature of assembly embedded resources is that they can be compiled with a strong name so that they can be stored in the GAC and that includes all satellite assemblies too.

Binary Resource Provider

Binary resources refer to the compiled binary resource .resources files that are generated when an Xml file is compiled using the Resource Generator utility ResGen.exe. The Binary Resource Provider enables you to extract resources directly from these files without having to embed them into an assembly. The Binary Resource Writer enables you to edit these binary files also without the need for a source Xml file. Reading resources from a binary file is very fast too as binary resource files hold their values as serialized CLR types. Changes can be made to these files without needing to re-compile and re-install the associated application assemblies.

Internationalized versions of binary resources reside in sub folders below the location of the neutral resources file. The sub folders take the name of the associated culture that the resources represent (see assembly resource provider above).

Binary resources cannot be stored in the GAC.

The Binary Resource Provider needs the full path name to the neutral resource file and uses its name, minus the extension, as the resource base name.

Xml Resource Provider

Xml resources refer to the source resource .resx files that are usually used to edit resources. Visual Studio uses Xml resource files as source files for resources. The Xml Resource Provider enables you to extract resources directly from these files without having to compile or embed them into an assembly first.. Reading resources from an xml file is slower than from binary files as the xml has to be parsed and resource values converted into their CLR types, however this is only done once on the first time that resources are requested from the file. Changes can be made to these files without needing to re-compile and re-install the associated application assemblies. Although a resource writer is available to edit these files, as they are Xml then if you know what you are doing you can use a simple text editor to make urgent changes. Beware, any mistakes will cause your application to fail.

Internationalized versions of xml resources include their associated culture name in the file name (see assembly resource provider above).

Xml resources cannot be stored in the GAC.

The Xml Resource Provider needs the full path name to the neutral resource file and uses its name, minus the extension, as the resource base name.

Data Resource Provider

Data resources refer to resources held in a database. The Resource Application Provider uses the Data Access Application Block for access to such a database, thus any database that you can configure in the Enterprise Library, including Custom Data Access Providers, can be used as a resource store. One caveat, however; is that the scripts for creating the Resource database are supplied as SQL scripts only. Having said this, there is only one table and four stored procedures so setting up the table and whatever equivalent to the stored procedures should not be an arduous task.

The supplied DataResourceWriter can be used with any IResourceWriter enabled resource editor including the excellent example from Guy Smith-Ferrier mentioned in his book .NET Internationalization. I have a mind to provide an API to his set of tools in a future release.

Internationalized versions simply use a culture column in the Resources table to segregate the culture sets. In addition there is a resource base name feature that enables you to segregate resources into subsets for performance and manageability reasons. Imagine using a single database for all of your resources for your enterprise. If this means storing 100,000 resources you don't want to be reading them all each time an application is loaded.

The Data Resource Provider is ideal for large enterprises and scalable applications and suits the provision of resources to assemblies stored in shared folders or the GAC alike.

Custom Resource Provider

This is a must for all Enterprise Library application blocks and is fully documented in the help files. Providing a custom provider complies with the rule that all applications blocks should be extensible. The Custom Resource Provider, therefore, enables any developer to create their own resource providers for use with the Resource Application Block. See Extending the Resource Application Block for details on how to create custom resource providers.

Last edited Feb 27, 2008 at 11:53 PM by ewdev, version 10


No comments yet.