title: Web API, odata v4 and Castle Windsor
body: <p>I have WebApi project with ODataController and I'm trying to inject some dependency into MyController. I was following this <a href="http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/" rel="nofollow">blogpost</a> by Mark Seemann.</p>
  
  <p>Consider code below.</p>
  
  <p>Problem is, that when is MyController creating, I got exception inside WindsorCompositionRoot Create method on this line,</p>
  
  <pre><code>var controller = (IHttpController)this.container.Resolve(controllerType);
  </code></pre>
  
  <blockquote>
    <p>An exception of type 'Castle.MicroKernel.ComponentNotFoundException'
    occurred in Castle.Windsor.dll but was not handled in user code</p>
    
    <p>Additional information: No component for supporting the service
    System.Web.OData.MetadataController was found</p>
  </blockquote>
  
  <p>Any idea how to fix this?
  Thank you.</p>
  
  <p><strong>My controller:</strong></p>
  
  <pre><code> public class MyController : ODataController
  {
      private readonly DataLayer _db;
  
      public PrepravyController(DataLayer db)
      {
          _db = db;
      }
  }
  </code></pre>
  
  <p><strong>CompositonRoot:</strong></p>
  
  <pre><code>public class WindsorCompositionRoot : IHttpControllerActivator
  {
      private readonly IWindsorContainer container;
  
      public WindsorCompositionRoot(IWindsorContainer container)
      {
          this.container = container;
      }
  
      public IHttpController Create(
          HttpRequestMessage request,
          HttpControllerDescriptor controllerDescriptor,
          Type controllerType)
      {
          var controller =
              (IHttpController)this.container.Resolve(controllerType);
  
          request.RegisterForDispose(
              new Release(
                  () =&gt; this.container.Release(controller)));
  
          return controller;
      }
  
      private class Release : IDisposable
      {
          private readonly Action release;
  
          public Release(Action release)
          {
              this.release = release;
          }
  
          public void Dispose()
          {
              this.release();
          }
      }
  }
  </code></pre>
  
  <p><strong>Global asax</strong>:</p>
  
  <pre><code> var container = new WindsorContainer();
          container.Install(new RepositoriesInstaller());
  
          GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorCompositionRoot(container));
                      GlobalConfiguration.Configure(WebApiConfig.Register);
  </code></pre>