title: MVC3 ImportMany on Constructor Parameter for Exported Controller
body: <p>I have a controller that is exported using MEF and loaded by the Controller factory.</p>
  
  <pre><code>    [Export(Controller)]
      public class MyController : Controller
      {
  
          private IRepository MyRepsoitory;
  
          [ImportMany]
          public IEnumerable&lt;MyImportedItem&gt; TestImportItems {get;set;}
  
          public MyController([ImportMany]IEnumberable&lt;MyImportedItem&gt; items, [Import]IRepository repository)
          {
              // items here is always null
              // However if I grab the container that the ControllerFactory used and tell it ComposeParts on this the TestImportItems will be filled with 50+ items
              // repository however is instantiated appropriately. 
  
              GlobalItems.Container.ComposeParts(this);
              //Now TestImportItems if filled but my items parameter alway null... how do I get constructor to fill
  
          }
  
      }
  </code></pre>
  
  <p>So MEF creates MyController but only creates the repository and sends null for the ImportMany even though it can fill the property later with the same Container.</p>
  
  <p>What's also odd is if I do something that breaks one of the  items the creation of MyConroller breaks in ControllerFactory.. as if it checks that is has parts for the constructor but never pushes them to the IEnumerable parameter.</p>
  
  <p>What am I missing?</p>
  
  <p>Obviously I have the parts available if the same Container works for .ComposingParts on (this) (and I reflected the catalog which has appropriate import/export Parts available at time of creating the Controller.</p>
  
  <p>I could rewrite my class to use the filled Property but I would really like my importing constructor to get a filled collection.</p>
  
  <p>UPDATE:</p>
  
  <p>If I add a simple wrapper class for the import many MEF will load the [ImportMany] parameter.</p>
  
  <p>So the following will fill the IEnumerable for me...</p>
  
  <pre><code>public MyController(TestImportClass test, [Import]IRepository repository)
  {
      //test.Items != null
  }
  
  public class TestImportClass
  {
  
      public IEnumberable&lt;MyImportedItem&gt; Items {get;set;}
  
      [ImportingConstructor]
      public TestImportClass([ImportMany]IEnumberable&lt;MyImportedItem&gt; items)
      {
          this.Items = items;
      }
  }
  </code></pre>
  
  <p>I am using a "Convention" system in my actual code to mark the Controller for Export.  Maybe for some reason that is causing MEF to not understand the Import on initial Constructor Parameter?  If that were the case though i am not sure why my IRepository always gets filled?</p>