I have a class that implements two behavioral interfaces

class StageManager : IMoveStages, IProvideEncoderPulseScale

I registered both interfaces to the same concrete class.

Forward<IMoveStages, IProvideEncoderPulseScale>();

The hardware controller, IMoveStages, is wrapped in error recovery logic (using Dynamic Proxy and the StructureMap DSL)

IfTypeMatches(type => typeof(IMoveStages)
    .InterceptWith((ctx, target) =>
            new RecoveryInterceptor()));

However, when I resolve IProvideEncoderPulseScale, I get null! Allow me to fast-forward past the debugging…

I told Dynamic Proxy to proxy the concrete that was resolved for IMoveStages. So we get something like class MoveStages_Proxy : IMoveStages. StructureMap tried to forward the resolution of IProvideEncoderPulseScale, but the proxy only implements IMoveStages! Only the proxy’s target implements both interfaces.

I implemented the quick fix and chained the interface declarations

interface IMoveStages : IProvideEncoderPulseScale

The real solution is to instruct Dynamic Proxy to proxy the target and all its interfaces, but only intercepting the actual target interface. Krzysztof’s post shows how to do it “manually”. But, I have a system-wide interceptor that goes on a few dozen interfaces/targets. I don’t want to specify every additional interface on every target explicitly.

// not sustainable!
    new[] { typeof(IProvideEncoderPulseScale) },
    new RecoveryInterceptor())

I think that some reflection like this would work. Get all interfaces on the target that aren’t your own interface.

var additionalInterfaces = target
    .Where(interface => !(interface is target));

    new RecoveryInterceptor());