title: How do I resolve an array with Unity and pass a parameter to one of the items in the array?
body: <p>So here's my factory method which takes a parameter...</p>
  
  <pre><code>            container.RegisterInstance&lt;Func&lt;IProductInstance, IQuantityModifier[]&gt;&gt;(
              instance =&gt; container.Resolve&lt;IQuantityModifier[]&gt;());
  </code></pre>
  
  <p>Now <em>one</em> of the items returned by the array takes the IProductInsance parameter in its constructor. I can't figure out how to get Unity to pass the parameter in or, if I make the constructor argument a property instead, how to get Unity to set the property. No amount of dependency overrides, injection parameters etc. seem to do anything.</p>
  
  <p>Of course both of these situations would be easy if I was resolving a single instance but with an array Unity doesn't seem to fully process each item.</p>
  
  <p>Any ideas? What I've ended up doing is stuff like this...</p>
  
  <pre><code>            container.RegisterInstance&lt;Func&lt;IProductInstance, IQuantityModifier[]&gt;&gt;(
              instance =&gt;
                  {
                      var items = container.Resolve&lt;IQuantityModifier[]&gt;();
  
                      QuantityModifier item = items.OfType&lt;QuantityModifier&gt;().SingleOrDefault();
  
                      if (item != null)
                      {
                          item.ProductInstance = instance;
                      }
  
                      return items;
                  };
  </code></pre>
  
  <p>I suppose ideally the item that requires the parameter would be created by a factory but then Unity would have to pass the correct value into the factory and execute it.</p>
  
  <p>Cheers, Ian.</p>