using Microsoft.Practices.EnterpriseLibrary.PolicyInjection; // Initialize the Policy Injection application block var provider = new EPServiceProvider(); var policy = provider.PolicyInjection; // Use the policy to create instances of classes var obj = policy.Create();
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection; using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; // Initialize the Policy Injection application block with custom policies var provider = new EPServiceProvider(); var config = ConfigurationSourceFactory.Create(); var settings = config.GetSection(PolicyInjectionSettings.SectionName) as PolicyInjectionSettings; var policy = new PolicyInjection(policy => policy.Policies.Configure(settings.Policies)); // Use the policy to create instances of classes var obj = policy.CreateIn this example, the EPServiceProvider is created and initialized with custom policies for Policy Injection. The configuration settings are loaded from the app.config file using the ConfigurationSourceFactory. The policy is then created with the custom settings and used to create an instance of the MyClass class using the Create method.();