This project is read-only.

Resource Application Block 3.1

The Resource Application Block is all about resource management, localization and globalization. The Resource Application Block gives developers a provider model to get to resources from a variety of different sources and source types using the features of the Enterprise Library 3.1. All configuration of those resources naturally uses the Enterprise Library Configuration Console.

The developer is not limited to the providers out-of-the-box but can extend the block by adding providers of their own in the normal Enterprise Library extensible fashion.

Main Features

The following are the main features associated with the Resource Application Block:
  • Greater flexibility to choose how you host your resources. With the Resource Application Block you can now choose whether to centralise or distribute resources, whether to leave resources in editable files rather than embed into assemblies, pull in resources from other projects and thus treat resources like reusable modules as per the Object Oriented paradigm,
  • You can use either the stand-alone Enterprise Library Configuration Console or the Visual Studio integrated Console to manage all Resource Application Block settings.
  • You have a choice of resource providers to manage resources from a variety of sources such as assembly embedded resources, xml resources (.resx files), binary resources (.resources files) and database resources (any DB you can get to from the Data Access Application Block).
  • If you need to manage resources from a source type not currently supported then you can extend the application block by creating custom resource providers
  • You can generate strongly typed resource classes for any resource provider type directly from the Enterprise Library Configuration Console in either C# or VB.
  • A web resource provider is included to enable the developer to use the Resource Application Block with the localization features provided within ASP.NET. This works for both local and global resources.
  • All Resource Application Block managers are based on an extended ComponentResourceManager to enable reflection-style resource assignments to be made to Windows Forms component properties using the ApplyResources method within the ExtendedComponentResourceManager. Unfortunately, owing to the current closed nature of the Windows Forms designer CodeDomProvider model, with respect to localization, it has not been possible to extend the full Windows Forms localization feature, however see Windows Forms Designer for what you can do with the ExtendedComponentResourceManager.
  • A resource provider presents the developer with an appropriate resource manager type. Each resource manager supported within the Resource Application Block is provided with a corresponding resource writer to enable editing of the various resource storage types using any IResourceWriter enabled resource editor. These resource writers also support the extended data node interface allowing for comments, file references and custom types to be stored (except for binary resource files that do not support comments).
  • Management and monitoring features include Windows Active Directory Group Policy integration and instrumentation features such as Performance Counters, Windows EventLog logging and WMI events.

Key Uses

If you need convincing as to why you would use this block, have a look at the following reasons:
  • You need to localize your application. The Resource Application Block gives you way more choices for managing localization than with standard means.
  • You have a large number of resources spread between many files. The standard approach is to hold a set of resources for each assembly of an application. If you have a large number of assemblies in your application and you are supporting several different cultures then the number of resource files can be considerable, managing these files and managing translators and translations etc becomes a complex operation. You can use the Resource Application Block to centralise those resources or at least break them down into a manageable set. The database provider is an ideal choice when things start to get out of hand.
  • You think you might need to manage some of your resources on-the-fly without having to re-compile and re-install assemblies each time. The Resource Application Block can provide resources directly from source files (e.g. .resx or .resources files) and does not hold those files open once read. This allows for on-the-fly changes to resource values e.g. spelling corrections, word replacement, change of colour etc.
  • You may need to change from assembly embedded resources to a database as an application scales up. Because all resource storage types are managed through configuration it makes it very easy to swap from one storage type to another.

A Quick Code Sample

The following code sample shows the basic function of the block, how to get the default resource manager and use its resources. Note that an indexer is used, based on a string key and an optional type (string is the default) to get at the resources. The standard GetString(), GetObject() and GetStream() methods are still available however:

// get the default resource manager. Note: this is an EntLibContrib.Resource.ResourceManager NOT System.Resources.ResourceManager
ResourceManager rm = ResourceFactory.GetResourceManager();
// get a string resource
string myString = rm["StringKey"];
// get an integer resource, this works for any type of resource
int myInt = (int)rm["IntegerKey", typeof(int)];
// get an audio resource, you would normally need to use the GetStream() method for this type of resource.
UnManagedMemoryStream myAudio = (UnManagedMemoryStream)rm["AudioKey", typeof(UnManagedMemoryStream)];

This next code sample shows how to get a named resource manager instance, set a specific culture and also how do do string formatting using the optional params parameter of the indexer:

// get the "named instance" resource manager, this is the name you have given the configured resource manager in the console.
ResourceManager rm = ResourceFactory.GetResourceManager("named instance");
// set the culture to generic french.
rm.CultureInfo = new CultureInfo("fr");
// get a formatted string resource and format the string
string friendlyResponse = "bonjour";
string myFormattedString = rm["FriendlyMessageKey", friendlyResponse];

If the resource value is something like "mon ami dit {0}" then myFormattedString will contain "mon ami dit bonjour". Note: you can have more than one replaceable format string parameter in the same fashion as String.Format().

Installing the Assemblies

When you build the Resource Application Block the assemblies are compiled without a strong name key. If you want to put these assemblies into the GAC then you will need to assign a strong name key to each assembly and recompile (this is not neccessary for any design.dll assembly). If you use the BuildLibraryAndCopyAssemblies.bat console script then the assemblies are copied to the EntLibContrib bin folder. You can reference the assemblies from here for your application however; to use the Configuration console you will need to copy all of the following assemblies to your installation of the Enterprise Library Configuration Console which is usually in C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin:

The Resource Application Block 3.1 consists of the following assemblies:
  • EntLibContrib.Resource.dll - the main assembly for the block
  • EntLibContrib.Resource.Store.dll - the Resource Application Block uses itself to supply its own resources. These are held in this resource only assembly.
  • EntLibContrib.Resource.Database.dll - to comply with the rule that all application blocks must be able to work independantly of any other block, the data resource manager and provider, which has a dependancy on the Data Access Application Block was separated out to its own assembly.
  • EntLibContrib.Resource.Configuration.Design.dll - the plug-in interface to the Enterprise Library Configuration Console for the Resource Application Block.
  • EntLibContrib.Resource.Database.Configuration.Design.dll - the plug-in interface to the Enterprise Library Configuration Console for the Resource Application Block data provider.

What Next?


I did not get much feedback from the Resource Application Block versions 1.1 and 2.0 so I very nearly did not bother with version 3.1 until I read .NET Internationalization by Guy Smith-Ferrier so my thanks to him for the inspiration and some neat ideas.

I know it might sound like a cliche but I must include my wife Margaret too. I have three young boys and you don't get to write this kind of stuff whilst carrying out a full program of fatherly responsibilities... Off to read Rupert Bear to the 6 year old, I will try not to localize him or turn Pong-Ping into a Frenchman.

Last edited Dec 15, 2009 at 1:18 PM by ewdev, version 21


tonyeka Jul 21, 2009 at 6:00 PM 
Hi there, just wondering whether there will be any attempt to have a WPF sample using this block?

breen May 1, 2008 at 5:10 PM 
Any place I can get ahold of versions 1.1 and 2.0 of the Resource Application Block? I need it for some older projects. Your links where you posted it to GotDotNet are gone now that the side is defunct.


ewdev Apr 11, 2008 at 5:15 PM 
Hi John,

Yes it is all available but only in source code form at the moment. Simply download the latest source code and you will have the lot. I believe Tom Hollander will be producing a new release with this block in it at some stage.

johnwsaundersiii Apr 3, 2008 at 4:17 PM 
Dumb question - is this available yet? If so, where is it, either in source or binary format?