title: Configuring Unity to intercept an interface using both an InterfaceInterceptors and a method interceptor
body: <p>What I'm trying to do is to make unity register two different InterceptorBehaviors on an object. I've found two examples of applying interceptors through the container. They seem to work individually but when I attempt to use them together it appears that the Interface interception behavior doesn't attempt to determine the attribute based behaviors. Is there something that I am doing wrong in how I'm configuring the container?</p>
  
  <p>Here is the interface...</p>
  
  <pre><code> public interface ISomeInterface{
  
      [NullWarningBehaviorAttribute]
      void WillLogWarningIfNull(string someValue);
  
  
      void WillThrowException();
  }
  </code></pre>
  
  <p>Here is the implementing class...</p>
  
  <pre><code>public class SomeImplementation : ISomeInterface {
  
      [NullWarningBehaviorAttribute]
      public void WillLogWarningIfNull(string someValue) {
  
      }
  
      public void WillThrowException() {
      }
  }
  </code></pre>
  
  <p>Here is the Attribute based behavior...</p>
  
  <pre><code> public class NullWarningBehavior : ICallHandler{
  
      public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
      {
          return getNext()(input, getNext);
      }
  
      public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
      {
          return getNext()(input, getNext);
      }
  
      public int Order { get; set; }
  }
  
  public class NullWarningBehaviorAttribute : HandlerAttribute {
      public override ICallHandler CreateHandler(IUnityContainer container) {
          return container.Resolve&lt;NullWarningBehavior&gt;();
      }
  }
  </code></pre>
  
  <p>Here is the interface interception behavior</p>
  
  <pre><code>public class ExceptionLoggingBehavior : IInterceptionBehavior {
  
      public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) {
          return getNext()(input, getNext);
      }
  
      public IEnumerable&lt;Type&gt; GetRequiredInterfaces() {
          return Type.EmptyTypes;
      }
  
      public bool WillExecute {
          get {
              return true;
          }
      }
  }
  </code></pre>
  
  <p>This code will correctly detect the attribute and call the constructor method on the NullWarningBehaviorAttribute in order to create the ICallHandler.</p>
  
  <pre><code>var uc = new UnityContainer();
          uc.AddNewExtension&lt;Interception&gt;();
  uc.RegisterType&lt;ISomeInterface, SomeImplementation&gt;(
            .Configure&lt;Interception&gt;()
            .SetDefaultInterceptorFor&lt;ISomeInterface&gt;(new InterfaceInterceptor());
  </code></pre>
  
  <p>Configuring the container in this fashion will create the interface interceptor successfully.</p>
  
  <pre><code>  uc.RegisterType&lt;ISomeInterface, SomeImplementation&gt;(
        new Interceptor&lt;InterfaceInterceptor&gt;(),
        new InterceptionBehavior&lt;ExceptionLoggingBehavior&gt;());
  </code></pre>
  
  <p>I was thinking that I could simply combine the two methods but when I do that the NullWarningBehaviorAttribute CreateHandler method never gets called. Is there a specific way of configuring this?</p>
  
  <pre><code> uc.RegisterType&lt;ISomeInterface, SomeImplementation&gt;(
              new InterceptionBehavior&lt;ExceptionLoggingBehavior&gt;())
            .Configure&lt;Interception&gt;()
            .SetDefaultInterceptorFor&lt;ISomeInterface&gt;(new InterfaceInterceptor());
  </code></pre>