title: Castle Windsor - Register all interfaces with factory method
body: <p>I have a number of interfaces:</p>
  
  <ul>
  <li><code>IFirstProvider</code></li>
  <li><code>ISecondProvider</code></li>
  <li><code>IThirdProvider</code></li>
  <li>etc..</li>
  </ul>
  
  <p>I'm trying to register all these interfaces so that they use a factory method to get the instance:</p>
  
  <pre><code>container.Register
      (  
          AllTypes
              .FromThisAssembly()
              .Where(t =&gt; t.IsInterface &amp;&amp; t.Name.EndsWith("Provider"))
              .Configure(c =&gt; c.UsingFactoryMethod(f =&gt; f.Resolve&lt;DictionaryAdapterFactory&gt;().GetAdapter&lt;object&gt;(c.ServiceType, session))
      );
  </code></pre>
  
  <p>But this doesn't seem to work.  Instead, I have to use a <code>for</code> loop to register all these interfaces:</p>
  
  <pre><code>List&lt;Type&gt; providers = new List&lt;Type&gt;
      (
          Assembly
              .GetExecutingAssembly()
              .GetTypes()
              .Where(x =&gt; x.IsInterface &amp;&amp; x.Name.EndsWith("Provider"))
      );
  
  foreach (Type provider in providers)
  {
      Type temp = provider;
  
      container.Register
          (
              Component
                  .For(temp)
                  .UsingFactoryMethod(f =&gt; f.Resolve&lt;DictionaryAdapterFactory&gt;().GetAdapter&lt;object&gt;(temp, session))
          );
  }
  </code></pre>
  
  <p>Is there a better way to register these interfaces besides using a <code>for</code> loop?</p>