title: Castle Windsor cannot resolve type in WebApi
body: <p>I created a WebApi project and configured Castle Windsor as DI container.</p>
  
  <p>When I deploy my WebApi on my WebServer, everything is working fine until I restart the web server (I'm using <code>IIS</code>) by clicking on the restart button or by executing the <code>iisreset</code> command. After that, I always have the following error:</p>
  
  <blockquote>
    <p>No component for supporting the service
    XXX.ICategoryDomainService
    was found</p>
  </blockquote>
  
  <p>When running my project in debug mode inside <code>Visual Studio</code>, this problem seems to happen randomly. But each time I do a full <code>Clean/Rebuild</code>, it's then working at least once. Stopping/Starting the project many times (always inside <code>Visual Studio</code>) brings the problem back. When the exception raised, I inspected the state of the Container and everything seems to be ok</p>
  
  <p><img src="https://i.stack.imgur.com/qLrFT.png" alt="Castle Windsor Configuration"></p>
  
  <p><strong>Update:</strong></p>
  
  <p>Ok, I finally managed to find where the problem was (but I do not have a proper solution for now).<br>
  I'm doing a registration in a Framework dll that scans all types of my current project and tries then to registered automatically some of these types... </p>
  
  <p><strong>In a Framework Library:</strong></p>
  
  <pre><code>IEnumerable&lt;IInstaller&gt; installers = this.Container.ResolveAll&lt;IInstaller&gt;();
  foreach (IInstaller installer in installers)
  {
      installer.Install(this.Container);
  }
  </code></pre>
  
  <p>This is how IInstaller is registered:</p>
  
  <pre><code>this.Container.Register(Classes
      .From(ApplicationDomain.Current.ConcreteClasses)
      .BasedOn&lt;IInstaller&gt;()
      .WithServiceAllInterfaces()
      .LifestylePerWebRequest());
  </code></pre>
  
  <p>A small extensions method (always in Framework)</p>
  
  <pre><code>public static void RegisterAllServices(this IWindsorContainer container, 
      IEnumerable&lt;Type&gt; types)
  {
      container.Register(Classes
          .From(types)
          .BasedOn&lt;IService&gt;()
          .WithServiceAllInterfaces()
          .LifestyleTransient());
  }
  </code></pre>
  
  <p><strong>An installer in my project</strong></p>
  
  <pre><code>public class BusinessInstaller : IInstaller
  {
      public void Install(IWindsorContainer container)
      {
          Type[] types = typeof(BusinessInstaller).Assembly.GetTypes();
          container.RegisterAllServices(types);
      }
  }
  </code></pre>
  
  <p>It's very weired, but this is what I can observe: The extensions method <code>RegisterAllServices</code> is only called when I do a full rebuild. After that, in debug mode, I can see that the debugger just steps over an never get into this method BUT the types are registered anyway (but probably in a wrong way, because Windsor is not able to resolve them!). </p>
  
  <p>The temporary fix is to register all my classes in the BusinessInstaller. Then it works... but it's not optimal, it would be better if everything could be automatically registered...</p>