Configuration in the Stock Trader V2 Reference Implementation

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

patterns & practices Developer Center

On this page:
Requirements | Configuration Architecture | More Information

In this section, we'll discuss how the StockTrader V2 application uses configuration files.

Requirements

These were the requirements for configuration:

  • It should be possible to update Silverlight XAML configuration files without having to change the XAP files. This means that the XAML configuration files should be downloaded from the server and not embedded in the XAP.
  • There are some validation rules that should be defined in configuration. These validation rules should be shared between the web services and the Silverlight application.
Hh852723.note(en-us,PandP.51).gifMark Says:
Mark We really needed the ability to be able to change an application's configurationwithout having to recompile it. It happens quite often that we need to add or change some of the validation rules that are defined in configuration. I also sometimes need to change the logging settings to diagnose problems. It's not very practical if I need a developer to compile a new version for me every time this happens.

Configuration Architecture

Both the web services layer and the Silverlight application use Enterprise Library for configuration. The following diagram shows how Enterprise Library is configured both on the web server and in Silverlight.

Follow link to expand image

Web.config contains the configuration for the web server. For example, it contains configuration for the Exception Handling block, which is set to log all errors to the event log. The web.config file uses a file-based configuration source to reference the validation rules in a separate configuration file.

The Silverlight Stock Trader V2 application uses two separate XAML configuration files. The first file, StockTraderRI.Silverlight.xaml, contains the main configuration for the Logging, Exception Handling, and Caching blocks. The second file, validation.xaml, contains the validation rules that should be shared by both the Silverlight application and the web server.

The XAML configuration files have been created by first creating regular application configuration files (StockTraderRI.Config and validation.config) and then using the wizard to generate the XAML files.

The Enterprise Library 5.0 Silverlight Integration Pack has out-of-the box support for reading a single XAML configuration file from the XAP or downloading a single XAML configuration file from the server. For Stock Trader V2, we needed to download multiple configuration files and merge them in order to support the sharing of validation rules between the client and the server.

Hh852723.note(en-us,PandP.51).gifSharon Says:
Sharon
                A common approach to merging two XAML files is to use a merge dictionary. Unfortunately, the Enterprise Library 5.0 Silverlight Integration Pack cannot use a resource dictionary or merged dictionary to store configuration information. A resource dictionary has an affinity with the UI thread, and that would cause issues when you use Enterprise Library from a background thread.</td>

The Stock Trader V2 application contains a class called the AsyncXAMLConfigurationMerger. This class was built to download several XAML files and merge them, since this feature is not supported by the Enterprise Library 5.0 Silverlight Integration Pack out of the box. When all the asynchronous downloads have completed, it will proceed to merge them and use the merged result to configure Enterprise Library.

The Merger only merges the top level nodes in a configuration file. This means that the entire configuration for a particular block must reside in a single file. For example, you can store validation configuration XAML in one file and put the configuration for other Enterprise Library blocks in a separate file, but you cannot spread validation configuration across multiple files.

More Information

In this chapter, we discussed how you can configure the Enterprise Library 5.0 Silverlight Integration Pack. We discussed how you can use the configuration console to create application configuration files, which can then be converted into XAML configuration files. We also looked at several options for consuming these XAML configuration files in a Silverlight application.

For more information on creating application configuration files using the configuration console, please refer to the chapter Using Configuration Tools in the Enterprise Library documentation on MSDNĀ®.

Next Topic | Previous Topic | Home

Last built: July 8, 2011