Policy Injection Application Block (PIAB) is a newly introduced app block in Enterprise library 3.0.
Enterprise Library assist in Aspect-Oriented software development by providing application blocks which solves common problems across layers of an application.
PIAB helps in aggregating these blocks and apply them to the application execution thread using configurable policies without requiring to call individual blocks from app code.
The main objectives of this block are :
- Ability to apply policies to type instances at runtime based on configurable policies which can be changed without changing code.
- Ability to build custom handlers and matching rules for applying policies.
Some of the common scenarios where PIAB can be used are :
- Logging Method invocations
- Handling exceptions
- Validating Parameter Values
- Caching Method results
- Measuring Target Method Performance
The main steps in using PIAB are :
- Identifying the Object which needs to be intercepted and checking if it is interceptable. For Object to be interceptable it must meet one of the following conditions:
- Class must be derived from MarshalByRefObject
- Class must implement a known interface.
- Add the PIAB block to the app config file using the Enterprise Library tool
- Create a policy which will be applied to the application.
- Within policy create matching rules. There are some matching rules which come with block like assembly matching rule, Member name matching rule, etc. Custom matching rules can also be developed.
- Specifying the handlers to be executed in case rules matched. There are some default handlers which come with PIAB like authorization handler, logging handler, etc. Custom handlers can also be developed.
- Creating or Wrapping the target instances using the methods provided by PIAB to add a handler pipeline.
Apart from specifying in config file, handlers can also be applied using attributes provided by PIAB which makes sure that handlers get executed in all circumstances.
In my next post on this I will cover a tutorial on how to use PIAB.
- Caching App Block : Usage notes on Backing store
- Enterprise Library 3.0 : Released
- Tutorial - Using Validation Application Block
- Tutorial : Enterprise Library - Using Exception Handling Application Block
- Tutorial : Enterprise Library - Using Caching Application Block
- Tutorial : Enterprise Library - Using Logging Application Block