title: MEF Best practices: Where in the application I create container and where to call Compose()?
body: <p>I have decided to use MEF for a plugin pattern I have and found MEF easy to pick up and not intrusive at all. I looked at samples and found them very easy to work with.</p>
  
  <p>However, as soon as started implementing, I started struggling with the composition. Let's say I have a Class which has <code>[ImportMany]</code> on one of its properties. All examples I have seen, they create the Container in the class which has imports (let's call it <strong>composable</strong>) and basically <em>the class composes itself</em>. That might be OK for an example but surely putting knowledge of how the plugin gets populated is too much for the composable to know.</p>
  
  <p>I can happily create a singleton container and access it in my composable but again the composable has to explicitly call <code>Compose()</code> on itself and I am not happy with that either as it is like a dependency injection scenario where the class pro-actively calls the <code>Resolve()</code> on the container. So I do <strong>not</strong> want to use it <em>for just Service Location</em>.</p>
  
  <p>To make the matters worse I am also using Windsor Castle for DI and I am not sure how MEF and Windsor must work together.</p>
  
  <p>I have really looked around and have not been able to find any guidance and sample on how to do MEF right. Now it might be that I have not looked around or I do not know MEF well enough (which is true) but will value your views from the experience of actually using it in the real world.</p>