Enterprise Library 6.0 PolicyInjection

Topics: Policy Injection Application Block
May 13, 2013 at 11:34 AM
How to use PolicyInjection in Enterprise Library 6.0?
As we know, we can use logger and exceptionpolicy like this:
        IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
        var logWriterFactory = new LogWriterFactory(configurationSource);

        var exceptionPolicyFactory = new ExceptionPolicyFactory(configurationSource);
what about PolicyInjection?
May 13, 2013 at 4:39 PM
Assuming you have policy injection configured then you can use the following:
PolicyInjector policyInjector = new PolicyInjector(configurationSource);
BankAccount acct = new BankAccount();
IBankAccount account = PolicyInjection.Wrap<IBankAccount>(acct);

The above uses the static facade -- you can also use PolicyInjector directly:
PolicyInjector policyInjector = new PolicyInjector(configurationSource);

BankAccount acct = new BankAccount();
IBankAccount account = policyInjector.Wrap<IBankAccount>(acct);

Randy Levy
Enterprise Library support engineer
Support How-to