I hope you’re enjoying the new release of Enterprise Library! One of the more interesting inclusions in this release is the new Policy Injection Application Block. The goal of the PIAB is to make it easier to separate cross-cutting concerns from business logic, using declarative policies. A policy consists of a set of matching rules, which indicate which objects and methods the policy applies to, and a chain of handlers, which are objects that execute before and/or after a method is called to accomplish interesting stuff. The PIAB ships with 6 handler types that provide implementations for logging, validation, exception handling, authorization, caching and performance counters.
Using the PIAB intelligently in your application should allow you to write simpler, more maintainable code. However a few people have already pointed out that this separation of business logic from cross-cutting concerns has the potential to cause confusion, since it won’t be possible to understand the complete behavior of the application by looking only at the code. While this problem can be mitigated by applying handlers directly using handler attributes or indirectly via the TagAttribute, I do agree that this style of development does carry a different set of risks to more traditional development styles.
To help take the mystery out of which policies will apply to which objects and methods, I put together a simple tool called the Effective Policy Viewer. This tool is not included in the Enterprise Library 3.0 installer; instead I’ve uploaded it directly to the EntLib CodePlex site, so we can more easily update it over time. Here’s the tool looks like:
The tool lets you load an assembly, and optionally a configuration file (if you don’t select a configuration file it will only look for handlers applied using attributes). The left-hand tree view control will show all of the namespaces, classes and members in the assembly. If a class appears greyed-out, it means that none of the members have policies applied to them. If the class is black, you can expand it to see which members have policies applied to them. Selecting a member will show the list of policies and handlers in the right-hand tree view control. The order that the handlers are listed in the control reflects the order that they will execute at runtime. Keep in mind, however, that policies will only run when objects are created or wrapped using the PolicyInjection class, but this tool can’t verify that you’re doing this.
Please let us know if you have any feedback or problems with this tool. This was built in my spare time so it hasn’t gone through any real review or tests, but if there are problems then it shouldn’t take long to update it. If anyone feels like “supercharging” the tool and sharing your changes, please go right ahead!