The Policy Injection QuickStart Configuration

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.

The Policy Injection QuickStart ships with a defined configuration included in the App.config file. You can view or change these settings in three different ways:

  • In Visual Studio Solution Explorer, double-click App.config (or right-click it, and then click Open) to display the configuration file content as XML in the standard XML editor window. In this view, you can see the actual content or the configuration file and the elements and attributes for each section. However, you will usually find it easier to understand and manage configuration using one of the two following approaches.
  • In Visual Studio Solution Explorer, right-click App.config, and then click Edit Enterprise Library Configuration. This opens the Configuration Editor add-in that Enterprise Library registers with Visual Studio when you install it. The Visual Studio Properties window shows the values of each node in the configuration tree, and allows you to edit them.
  • On the taskbar, click Start, point to AllPrograms, point to Microsoft patterns and practices, point to Enterprise Library 3.1 – May 2007, and then click Enterprise LibraryConfiguration. This opens the stand-alone Configuration Console. Click the Open button on the toolbar, navigate to the QuickStart folder, and select the App.config file. This view provides a comprehensive environment for editing configuration, but not as easily accessible as the Configuration Editor when you are working on a project in Visual Studio.

Figure 1 shows the App.config file for the Policy Injection QuickStart open in the Visual Studio Configuration Editor. In this screenshot, the main window (the area on the left in the screenshot) contains the configuration tree showing all the configured objects from Enterprise Library. The Properties window (the central pane) shows the properties for the selected node in the configuration tree, and the Solution Explorer window on the right shows the normal view of the solution files.

Ff649825.PI-QSTART-Config(en-us,PandP.10).gif

Figure 1
The QuickStart configuration open in the Visual Studio Configuration Editor

The QuickStart uses the following three matching rules provided with the Policy Injection Application Block:

  • Namespace Matching Rule. This is configured to select all members of classes that have the namespace PolicyInjectionQuickStart.BusinessLogic.
  • Member Name Matching Rule. This is configured to select only members named Withdraw.
  • Type Matching Rule. This is configured to select only classes of type BankAccount.

The QuickStart uses the following five handlers provided with the Policy Injection Application Block:

  • Logging Handler. This is configured to write log entries both before and after a method call with Priority 0 and Severity "Information".
  • Authorization Handler. This is configured with the operation name set to the "{method}" placeholder so that the authorization provider will apply the authorization rule identified by the current method name.
  • Performance Counter Handler. This is configured to update all counters except the "Total" counter.
  • Exception Handling Handler. This is configured to use the exception policy named "Bank Account Policy".
  • Validation Handler. This is added through attributes instead of through the configuration; therefore, it is not visible in Figure 1.

You can see in Figure 1, or by viewing the configuration yourself, that the QuickStart specifies the following two policies for the Policy Injection Application Block:

  • Authorize and Audit. This policy uses a Namespace Matching Rule to select classes for which the application block will generate a handler pipeline containing the Logging Handler and the Authorization Handler. The Namespace Matching Rule selects all members of classes that have the namespace PolicyInjectionQuickStart.BusinessLogic, within which the business object used by the QuickStart resides.
  • Exception Handling. This policy uses a Member Name Matching Rule and a Type Matching Rule to select classes for which the application block will generate a handler pipeline containing the Performance Counter Handler and the Exception Handler. The Member Name Matching Rule selects only members named Withdraw, and the Type Matching Rule selects only classes of type BankAccount. Therefore, as the rules combine with AND logic, the Exception Handling policy will only apply to the Withdraw method of the BankAccount class.

Other relevant sections in the configuration are the following:

  • Application Settings. This defines the three users Alice, Bob, and Charlie; and their employment types (Teller, Assistant, and Janitor).
  • Exception Handling Block. This specifies an exception handling policy named Bank Account Policy that generates an "Insufficient funds available" exception when an arithmetic exception occurs.
  • Logging Application Block. This specifies the formatting of the log file named Audit.log that the application generates within its run-time folder.
  • Security Application Block. This provides authorization for each user for the three tasks (Deposit, GetCurrentBalance, and Withdraw) based on each user's employment type.

Ff649825.note(en-us,PandP.10).gifNote:
Each time you build and run the QuickStart, Visual Studio copies the App.config file to the output directory for the project (the same directory where it creates the QuickStart executable file) and renames it to PolicyInjectionQuickStart.exe.config. If you want to use the Configuration Console to change any of the configuration settings, and you are planning to rebuild the solution, you must change the settings by opening the App.config file located in the QuickStart source directory. If you use the configuration tools or any other editor to change the configuration of the executable by editing the PolicyInjectionQuickStart.exe.config file, Visual Studio will overwrite these changes during the next successful build with the values in the App.config file.

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