title: Windsor TypedFactoryFacility, selecting a component based on argument type
body: <p>I have the following typed factory:</p>
  
  <pre><code>public interface IWorkerFactory
  {
      IWorker Create(IJob job);
  
      void Release(IWorker handler);
  }
  </code></pre>
  
  <p>This factory creates workers for a given job. The jobs all implement <code>IJob</code> but I want a couple of components which handle jobs of different types:</p>
  
  <p>e.g. both of these derive from <code>IJob</code></p>
  
  <pre><code>interface IJobType1 : IJob { }
  
  interface IJobType2 : IJob { }
  </code></pre>
  
  <p>And I want two worker types, one that deals with each type of <code>IJob</code></p>
  
  <pre><code>class Worker1 : IWorker
  {
      public Worker1(IJobType1 job) { }
  }
  
  class Worker2 : IWorker
  {
      public Worker2(IJobType2 job) { }
  }
  </code></pre>
  
  <p>I've tried this, but Windsor just picks the first implementation of <code>IWorker</code> it finds every time, attempting to pass an <code>IJobType1</code> to <code>Worker2</code> (or vice-versa) which throws an exception</p>
  
  <p>I've looked at the typed factory component selector but I can't quite work out how I would use this to the intended effect</p>
  
  <p>Is this possible or is it better to attempt to use a generic interface for my worker classes?</p>
  
  <p>Edit:</p>
  
  <p>Tried using a generic interface but that doesn't seem to give me the API I'm looking for...the key issue is that I don't really want to know what type the <code>IJob</code> is but I want the most appropriate <code>IWorker</code> instance to be created at resolution time.</p>
  
  <p>I'm calling it like this:</p>
  
  <pre><code>public void ProcessItem(IJob job)
  {
      IProcessingExceptionLog exLog = null;
      IWorker worker = null;
  
      try
      {
          worker = _workerFactory.Create(job);
  
          // Attempt to process                
          worker.Process();
      }
      catch (Exception ex) .... etc
  </code></pre>
  
  <p>Even if I do cast job to a more derived interface, Windsor still picks the first IWorker...it's not interested in checking the parameters of the method that closely</p>
  
  <p>I'd ideally like some way to intercept or customise the resolution process so that I can determine what the closest matching signature that accepts <code>IJob</code> is.</p>
  
  <p>I could try implementing a concrete factory based on the <code>IWorkerFactory</code> interface myself. It could look at all implementors of <code>IWorker</code> and determine which ones constructor matched the arguments closest, however, how do I resolve from the container in this instance as I won't have a container instance to use? I don't really like the idea of making the container static</p>