title: Use component id in Castle Windsor generic object configuration
body: <p>2 questions in one, but very much related.</p>
  
  <p>Is it possible with Castle Windsor to resolve a configuration entry such as -</p>
  
  <p>Assembly.Namespace.Object1`2[[${ComponentId1}],[${ComponentId2}]], Assembly</p>
  
  <p>Where ComponentId1 and ComponentId2 are defined as components. Castle Windsor doesn't seem to be resolving the ComponentId, it is just looking for ComponentId1 in the Castle.Windsor assembly.</p>
  
  <p>The second question comes in to play if you can't do the first question. If you have to use a full assembly reference instead of a ComponentId, how can you pass any parameters to the object being created? eg to set ComponentId1.Field1 = "blah", or pass something to the constructor of ComponentId1</p>
  
  <p>Hope that makes sense</p>
  
  <p>Update -</p>
  
  <p>Following the request for code I've knocked together the following -</p>
  
  <p>Objects</p>
  
  <pre><code>public class Wrapper&lt;T, T1&gt; where T : ICollector where T1:IProcessor
  {
      private T _collector;
      private T1 _processor;
  
      public Wrapper(T collector, T1 processor)
      {
          _collector = collector;
          _processor = processor;
      }
  
      public void GetData()
      {
          _collector.CollectData();
          _processor.ProcessData();
      }
  
  }
  
  public class Collector1 : ICollector
  {
      public void CollectData()
      {
          Console.WriteLine("Collecting data from Collector1 ...");
      }
  }
  
  public class Processor1 : IProcessor
  {
      public void ProcessData()
      {
          Console.WriteLine("Processing data from Processor1  ...");
      }
  }
  </code></pre>
  
  <p>repeated so 3 of each type of object in the example</p>
  
  <p>Config</p>
  
  <pre><code>&lt;components&gt;
  &lt;component id="Collector1"
             service="CastleWindsorPlay.ICollector, CastleWindsorPlay"
             type="CastleWindsorPlay.Collector1, CastleWindsorPlay"/&gt;
  &lt;component id="Collector2"
             service="CastleWindsorPlay.ICollector, CastleWindsorPlay"
             type="CastleWindsorPlay.Collector2, CastleWindsorPlay"/&gt;
  &lt;component id="Collector3"
             service="CastleWindsorPlay.ICollector, CastleWindsorPlay"
             type="CastleWindsorPlay.Collector3, CastleWindsorPlay"/&gt;
  &lt;component id="Processor1"
             service="CastleWindsorPlay.IProcessor, CastleWindsorPlay"
             type="CastleWindsorPlay.Processor1, CastleWindsorPlay"/&gt;
  &lt;component id="Processor2"
             service="CastleWindsorPlay.IProcessor, CastleWindsorPlay"
             type="CastleWindsorPlay.Processor2, CastleWindsorPlay"/&gt;
  &lt;component id="Processor3"
             service="CastleWindsorPlay.IProcessor, CastleWindsorPlay"
             type="CastleWindsorPlay.Processor3, CastleWindsorPlay"/&gt;
  &lt;component id="Wrapper1"
             type="CastleWindsorPlay.Wrapper`2[[CastleWindsorPlay.Collector1, CastleWindsorPlay],[CastleWindsorPlay.Processor3, CastleWindsorPlay]], CastleWindsorPlay" /&gt;
    &lt;/components&gt;
  </code></pre>
  
  <p>Instantiation</p>
  
  <pre><code>        var wrapper = (Wrapper&lt;ICollector, IProcessor&gt;) container.Resolve("Wrapper1");
          wrapper.GetData();
  </code></pre>
  
  <p>This brief example errors with this error message though -</p>
  
  <p>Can't create component 'Wrapper1' as it has dependencies to be satisfied. 
  Wrapper1 is waiting for the following dependencies: </p>
  
  <p>Services: 
  - CastleWindsorPlay.Collector1 which was not registered. 
  - CastleWindsorPlay.Processor3 which was not registered.</p>
  
  <p>The curious part about this is that I can get it to resolve Collector1 and Processor3 individually before the call to the wrapper, but the wrapper still can't see them.</p>
  
  <p>This is a basic example, the next thing I'd like to be able to do is when instantiating the Wrapper, set a property on the collector and/or processor. So it could be something like Collector.Id = 10, but set in the config where the wrapper is defined. Setting against the Collector component definition wouldn't work as I'd want to be able to instantiate multiple copies of each Collector, using different Id's</p>
  
  <p>Update 2</p>
  
  <p>What I'm actually trying to do is have -</p>
  
  <pre><code>&lt;components&gt;
  &lt;component id="Wrapper1"
             type="CastleWindsorPlay.Wrapper`2[${Collector1}(id=1)],[${Processor3}]], CastleWindsorPlay" /&gt;
  &lt;component id="Wrapper2"
             type="CastleWindsorPlay.Wrapper`2[${Collector1}(id=3)],[${Processor3}]], CastleWindsorPlay" /&gt;
    &lt;/components&gt;
  </code></pre>
  
  <p>Then have another object defined as </p>
  
  <pre><code>&lt;component id="Manager"
             type="CastleWindsorPlay.Manager,CastleWindsorPlay"&gt;
    &lt;parameters&gt;
      &lt;wrappers&gt;
        &lt;array&gt;
          &lt;item&gt;${Wrapper1}&lt;/item&gt;
          &lt;item&gt;${Wrapper2}&lt;/item&gt;
        &lt;/array&gt;
      &lt;/wrappers&gt;
    &lt;/parameters&gt;
  </code></pre>
  
  <p>Then finally in code just be able to call -</p>
  
  <pre><code>var manager = (Manager)container.Resolve("Manager");
  </code></pre>
  
  <p>This should return the manager object, with an array of wrappers populated and the wrappers configured with the correct Collector and Convertor.</p>
  
  <p>I know there are errors in the Castle config here, that's why I'm asking the question, I don't know how to set the config up to do what I'm after, or even if it's possible to do it in Castle Windsor</p>