title: Unity Factory Injection
body: <p>I have an interface like the below one which I inject into unity container.</p>
  
  <pre><code>public interface IMyInstanceFactory
  {
      IEnumerable&lt;IMyInstance&gt; GetAll();
  }
  </code></pre>
  
  <p>All <code>IMyInstance</code> are known before runtime i.e they can be setup within the bootstrapper and can be retrieved from unity. My concrete implementation for <code>IMyInstanceFactory</code> is as below:</p>
  
  <pre><code>public class MyInstanceFactory:IMyInstanceFactory
  {
      IUnityContainer _container;
  
      public MyInstanceFactory(IUnityContainer container)
      {
          _container = container;
      }
      public IEnumerable&lt;IMyInstance&gt; GetAll()
      {
          return _container.ResolveAll&lt;IMyInstance&gt;();
      }
  }
  </code></pre>
  
  <p>..and in my bootstrapper I do something like this:</p>
  
  <pre><code>container.RegisterType&lt;IMyInstance,MyInstance1&gt;;
  container.RegisterType&lt;IMyInstance,MyInstance2&gt;;
  container.RegisterType&lt;IMyInstance,MyInstance3&gt;;
  container.RegisterType&lt;IMyInstanceFactory,MyInstanceFactory&gt;;
  </code></pre>
  
  <p>This resolves everything beautifully. However, I do not want to take a dependency on the the container as such or implement <code>IMyInstanceFactory</code> just for this, is there a way I can set this up without implementing <code>IMyInstanceFactory</code>? Does Unity provide a facility for this?</p>
  
  <p>Something of this sort..</p>
  
  <pre><code>container.RegisterType&lt;IMyInstanceFactory,factory=&gt;factory.GetAll()&gt;().IsResolvedBy(unity.ResolveAll&lt;IMyInstance&gt;);
  </code></pre>
  
  <p>I know castle can do this, can Unity do something similar?</p>