title: Interception on .NET Core 2.0 Web API Controller By Using Autofac
body: <p>I am trying to use interceptions on .Net Core 2.0 WebApi Application by using Autofac but I couldnt succeed it on Controllers. What I try is</p>
  
  <p>First I created a basic webapi which has one default controller(ValuesController). Then I set up the autofac configuration as below. Project is working without any error, but interception doesnt seems to be running. What I am doing wrong ?</p>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>public void ConfigureContainer(ContainerBuilder builder)
  {        
      builder.Register(c =&gt; new CallLogger());
      builder.RegisterType&lt;ValuesController&gt;()
             .EnableClassInterceptors()
             .InterceptedBy(typeof(CallLogger));
  }
  </code></pre>
  
  <p><strong>CallLogger.cs</strong></p>
  
  <pre><code>public class CallLogger : IInterceptor
  {
      public CallLogger()
      {
          System.Console.WriteLine("XXXXX");
      }
      public void Intercept(IInvocation invocation)
      {
          Console.WriteLine($"Calling method {invocation.Method.Name} with parameters {(string.Join(", ", invocation.Arguments.Select(a =&gt; (a ?? "").ToString()).ToArray()))}... ");
  
          invocation.Proceed();
  
          Console.WriteLine("Done: result was {0}.", invocation.ReturnValue);
      }
  }
  </code></pre>
  
  <p><strong>ValuesController.cs</strong></p>
  
  <pre><code>[Route("api/[controller]")]
  [Intercept(typeof(CallLogger))]
  public class ValuesController : Controller
  {
      private readonly ITest _test;
      public ValuesController(ITest test)
      {
          _test = test;
      }
      // GET api/values
      [HttpGet]
      public IEnumerable&lt;string&gt; Get()
      {
          return new string[] { "value1", "value2" };
      }
      // GET api/values/5
      [HttpGet("{id}")]
      public string Get(int id, [FromHeader(Name = "TenantId")] string tenantId)
      {
          _test.Log("asdasdasda");             
          return tenantId + " =&gt; " + id;
      }
  
      // POST api/values
      [HttpPost]
      public void Post([FromBody]string value)
      {
      }
  
      // PUT api/values/5
      [HttpPut("{id}")]
      public void Put(int id, [FromBody]string value)
      {
      }
  
      // DELETE api/values/5
      [HttpDelete("{id}")]
      public void Delete(int id)
      {
      }
  } 
  </code></pre>