IoC-Caontainer as Catalog

Nov 9, 2009 at 12:39 PM

Hi guys.

My Question is:

Should i write a CustomCatalog for objects created by an IoC-Container(not unity) to use them in MEF -> CompositionContainer?

 

Thanks

alonso

Developer
Nov 9, 2009 at 5:44 PM

You could possibly write a custom catalog but that would require you to know everything in the IOC container which isn't always possible. Another way to accomplish this is to write a custom ExportProvider which doesn't provide an way to enumerate all exports but only needs to answer queries via GetExportsCore.

 

Nov 9, 2009 at 7:00 PM

Hi Alonso

You don't necessarily need a custom catalog to do that. MEF allows you to write custom export providers for talking to other sources such as an IoC. Here is a snippet that shows how you an integrate with Unity for example.

http://codepaste.net/s6w6az

If you look in the snippet, you will see there is a custom ExportProvider that accepts a CommonServiceLocator instance in it's constructor. CSL provides a common interface and wrappers for various IoC containers, that is perfect to use for this instance. You can get CSL and the adapters at CommonServiceLocator.codeplex.com.

Thanks

Glenn