Are Interceptors and InterceptionBehaviors reusable?

Topics: Policy Injection Application Block
Jun 11, 2010 at 2:14 PM

I am writing a decorator for IUnityContainer the job of which is to add policy injection for all the type/instances registered with it;

My RegisterType implementation looks like this.

 

public IUnityContainer RegisterType(Type from, Type to, string name, LifetimeManager lifetimeManager, params InjectionMember[] injectionMembers)
{
    if (IsInjectable(from) )
    {
        var interceptor = new Interceptor<TransparentProxyInterceptor>();
        var interceptionBehavior = new InterceptionBehavior<PolicyInjectionBehavior>();

        injectionMembers = injectionMembers == null
            ? new InjectionMember[] { interceptor, interceptionBehavior } 
            : injectionMembers.Append(interceptor,interceptionBehavior);
    }

    return _container.RegisterType(from, to, name, lifetimeManager, injectionMembers);
}
It seems to me that in the above example the interceptor and interceptionBehavior local variables can be promoted to fields that only need to be instantiated once per container.  I just want to verity that this is in fact a safe thing to do.

 

Jun 16, 2010 at 1:45 AM

Please post Unity questions in the Unity forum.