Policy Injection with Stand-alone Interception

Aug 9, 2011 at 11:21 AM

Hi Forum

I need to use a CallHandler/Policy Injection using Stand-alone interception.

I need to use the PerformanceCounterCallHandler. I can get it to work by configuration and also programatically by using a container.

There are several examples of using a container programatically (see link below). It is quite expensive this way. I need to be able to set it up using Standalone Interception. (Through the Intercept. class). As I read it - the interception should be the same whether it is used via a Container or the Intercept class. 

 

Registering Policy Injection Components
http://207.46.16.248/en-us/library/ff660881%28PandP.20%29.aspx

Using Interception in Applications
http://msdn.microsoft.com/en-us/library/ff660848%28v=pandp.20%29.aspx

 

Hope somone can help.

Best regards,
JAXN

 

 

 

 

 

 

 

 

Aug 9, 2011 at 11:57 AM

I figured it out. Here is the code:

    public static T HookMeUP<T>(T instance)
                   where T : class
        {
            var behaviors = new List<IInterceptionBehavior> { };

            var interceptor = new InterfaceInterceptor();

            var request = new CurrentInterceptionRequest(interceptor, typeof(T), instance.GetType());
            var policies = new InjectionPolicy[] { new AttributeDrivenPolicy() };
            var behaviour = new PolicyInjectionBehavior(request, policies, null);

            behaviors.Add(behaviour);

            return Intercept.ThroughProxy(instance, new InterfaceInterceptor(), behaviors);
        }