An easy way of enabling/disabling policies ?

Topics: Policy Injection Application Block
Jun 1, 2007 at 5:29 PM
Is there any way of disabling/enabling policies in PIAB ?
For example, supose you have different policies thas are used for meausuring performance of members
in different namespaces (I mean each policy with different namespaces and member matching rules).
Supose, that in a moment you are applying this policies and meausiring, for example, in a
testing environment. And you want easily disable some of this in production environment. Could you define
a custom matching rule that means "applies to no member at all" and add/remove this to disable/enable a policy ?
Thanks in advance.
Jun 1, 2007 at 5:35 PM
Try the ApplyNoPolicies Attribute.

Per the documentation:

"At run time, the Policy Injection Application Block combines policies defined in the application configuration with policies defined using directly applied attributes. However, developers can prevent the application of any policies to specific classes and class members, irrespective of the application configuration settings, by using the ApplyNoPolicies attribute."

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#
Jun 2, 2007 at 8:03 AM
In the scenario described, ApplyNoPolicies probably isn't appropriate. You don't want to recompile just to go from test to production.

I can see two approaches to this:
1) Use a "NeverMatches" custom matching rule as mentioned in the original post, and edit the config file.
2) Use the Environments feature in the config tool to define separate policies for test vs. production.

-Chris