views:

21

answers:

0

I am using Unity 2.0 as my IOC container and I have created a LifeTimeManger for remote types very similar to what is describe in this thread.

I have also implemented a IUnityContainer decorator for my client side container that attaches a policy injection interceptor for any types that have policies. The relevant code in the decorator 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);
}

The code that calls the decorator (for remote types) looks like this:

public static void RegisterRemoteType(this IUnityContainer container, WellKnownClientTypeEntry typeEntry)
{
    var type = typeEntry.ObjectType;

    container.RegisterType(type, type, new RemotingLifetimeManager(typeEntry));
}

The remoting LifetimeManager itself works just fine. The interception code is also working fine for non-remote types (the type gets wrapped in policy injection proxy if any of the matching rules in the config file apply to it.) However, if I apply similar rules to a remote type, what gets returned is the remote type proxy with no injection proxy.

In both local and remote scenarios, the from argument is an interface. The to argument is a concrete type for the local scenario or the same interface type when remote (as can be seen from the second code block).

I have been digging around in the unity code and online for a few days now with no luck on how to fix this. Any help would be greatly appreciated.