title: Getting legacy objects to be imported when they are not attributed as Exports in MEF
body: <p>I'm starting to use MEF to build up a plugin based application, and I'm slowly adding MEF to the mix.  There is a lot of existing code that does not have any MEF DNA yet, but I still want to get that code into the new objects that are being automatically created by composition.</p>
  
  <p>Let's make this concrete.</p>
  
  <p>I have a list of objects that implement the IFoo interface and operate on the application model in specific but useful ways.</p>
  
  <pre><code>interface IFooCool : IFoo {}
  
  class FooCool : IFooCool {...}
  
  interface IFooAwesome : IFoo {}
  
  class FooAwesome : IFooAwesome {}
  
  IEnumerable&lt;IFoo&gt; fooCollection = ProvidedTheOldFashionWay(not, yet, MEF);
  </code></pre>
  
  <p>Now, I want to create some useful tools that map the <code>IFooX</code> interfaces to various user actions like menu commands or button clicks.  </p>
  
  <pre><code>[Export(ITool)]
  class CoolTool : ITool
  {
      IFooCool _fooCool;
      [ImportingConstructor]
      CoolTool(IFooCool fooCool) 
      {
          _fooCool = fooCool;
      }
  
      [Export(MenuAction)]
      void DoSomething() { _fooCool.SomeWork(...); }
  }
  </code></pre>
  
  <p>Here's what I'd like to do:</p>
  
  <pre><code>var batch = new CompositionBatch();
  foreach(var foo in fooCollection)
  {
      batch.AddPart(foo);  //add those legacy objects to the batch
  }
  
  var catalog = new TypeCatalog(typeof(CoolTool));  //or assembly or directory, ...
  var container = new CompositionContainer(catalog);
  
  container.Compose(batch);
  </code></pre>
  
  <p>The <code>CoolTool</code> will be instantiated and the <code>FooCool</code> legacy object will be passed to it.  Then I can get the exported functions and display them nicely in the menu and off we go.  When the user clicks a menu item, the new <code>CoolTool</code> will use the existing functionality of the <code>IFooCool</code> interface to do something, well, cool.</p>
  
  <p>Of course, that doesn't work.  Since the legacy objects are not attributed as exports, adding them to the composition batch does not help.  In the code above, I'm adding the foo instances to the batch with <code>batch.AddPart(object)</code> instead of <code>batch.AddPart(ComposablePart)</code>.  The first method uses the attributed model to discover composable information from the object.  </p>
  
  <p>How can I use the second overload?  Can I wrap my existing non-MEF object in a ComposablePart on the fly?  Something like:</p>
  
  <pre><code>batch.AddPart(CreateComposablePart(typeof(IFooCool), foo));
  </code></pre>
  
  <p>BTW, I'm use preview 8 in a non-silverlight app.</p>