I have a WCF service hooked with a Unity interceptor and all calls to the WCF layer is intercepted by Unity for auditing purposes. However, Unity seems to intercept ALL calls to resolve the interface, whether the call originated from WCF or internally.
Consider the following code:
[ServiceContract]
public interface IMyUtilityService
{
[OperationContract]
void DoUtilityStuff();
}
[ServiceContract]
public interface IMyService
{
[OperationContract]
void DoStuff();
}
class MyService : IMyService
{
public MyService(IMyUtilityService myUtilityService)
{
}
public void DoStuff()
{
}
}
The service interfaces are registered with Unity with interception:
container.RegisterType<IMyUtilityService, MyUtilityService>(
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<PipelineInterceptor>());
container.RegisterType<IMyService, MyService>(
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<PipelineInterceptor>());
When a WCF call is made to IMyService I get the interceptor firing which is great and I can do some auditing. When IMyService is resolved, however, the interceptor triggers again as IMyUtilityService is injected into the IMyService constructor.
Is there a way to configure Unity to prevent this? Or is there a way inside the interceptor to determine that the interception was directly triggered by WCF? Or do I need to create a different interface layer to separate the external calls and the internal calls?