Policy Injection block in Enterprise Library

Topics: Policy Injection Application Block
Dec 9, 2010 at 7:06 AM
Edited Dec 9, 2010 at 7:11 AM

hi,

i want to know what is the significance of policy injection block in enterprise library.

plz reply.

Dec 9, 2010 at 7:24 AM

PIAB provides you the capability of intercepting public methods and properties of classes.  You would want intercepting them if you need to do common tasks such as logging, validation, exception handling, and authorization.  PIAB lets you do this stuff without adding codes to your actual method.  You would only need to make use of the existing call handlers or even build your own and do the configuration stuff to enable interception.

Unity also provides you this capability that's why in the 5.0 version of Enterprise Library , PIAB is actually just one way of doing interception in Unity.  See related thread.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 9, 2010 at 7:31 AM

hi sarah,

can u tell me without adding actual code for logging how i can call logging in PIAB.

 

Dec 9, 2010 at 7:51 AM

First, you need to make your class interceptable.  Refer to this topic on how to do this.

On the configuration side, here are the steps:

1. Open your configuration file in the Enterprise Library Configuration Tool by right clicking on it and select Edit Enterprise Library Configuration.

2. Add the Policy Injection settings.  (Blocks menu -> Add Policy Injection Settings)

3. Add a policy, give it any name you want.

4. Add a matching rule to that policy which would indicate what properties or methods that will be intercepted.  For example, if you want to intercept a method named "Execute", you can add a Member Name Matching Rule and enter the string "Execute" in the Member Names property.   There are other matching rules which you can use so check those out.

5. Add the Logging Call Handler to the same policy.  This will automatically add the Logging Settings in your config having a General category with a referenced Formatted Event Log Trace Listener.  Now, if you add the General category in the Categories property, this will then tells that for every method it intercepts, the logging will be done using the Formatted Event Log Trace Listener.  There are other properties which you can configure and they are pretty much self explanatory. 

You can check out the Policy Injection documentation for more information.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Dec 9, 2010 at 8:43 AM

i have downloaded the enterprise library version 4.0. but it does not contain configuration tool option.

how to get that??

Dec 14, 2010 at 1:06 AM

Did you have a different version previously installed in your machine?  Did you uninstall it prior to installing entlib 4.0 or do you need them both so they're both installed on your machine right now?  Are you getting a package load failure when opening Visual Studio? 

If you have 2 versions of entlib installed but don't necessarily need both of them, try uninstalling both, look for Enterprise Library keys in your registry specifically the following and delete them:

HKEYLOCALMACHINE\SOFTWARE\Microsoft\Enterprise Library {version}

HKEYCURRENTUSER\SOFTWARE\Microsoft\Enterprise Library {version}

Reinstall it again.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com