I'd like a dead simple explanation of policy injection for less-informed co-workers. Where is a good resource for this? I learned about policy injection from the entlib help files, which I'm sure aren't the best option.


What the EntLib calls Policy Injection, is really Aspect Oriented Programming. I wrote a post introducing the concepts of AOP on my blog a while back, maybe it'll be helpful.

Fredrik Kalseth
+2  A: 

The MSDN documentation for Policy Injection has a pretty clear explanation:

Applications include a mix of business logic and crosscutting concerns, and the two are typically intermingled—which can make the code harder to read and maintain. Each task or feature of an application is referred to as a "concern." Concerns that implement the features of an object within the application, such as the business logic, are core concerns. Crosscutting concerns are the necessary tasks, features, or processes that are common across different objects—for example, logging, authorization, validation, and instrumentation. The purpose of the Policy Injection Application Block is to separate the core concerns and crosscutting concerns.

Simply put, the PI block lets developers define a set of policies that specify the behavior of objects in the system. So your core business logic, such as the code that calculates profit per unit in a fiscal year (one concern), is separated from the logging of that execution of logic (another, but more often used, concern).

The same documentation says that the PI block is not AOP because:

  • It uses interception to enable only pre-processing handlers and post-processing handlers.
  • It does not insert code into methods.
  • It does not provide interception for class constructors.

So trying to look at PI from an AOP perspective can muddy the waters a bit.

Robert S.