MEF for Beginner (Catalogs) – part 10


MEF for Beginner (Catalogs) – part 10

this is the 10th post of the MEF for Beginner series, the series TOC is available here.

this post will focus on Catalogs.

 MEF, export, import, importmany, extention, ioc, catalogs, composition

What is MEF Catalogs?

MEF container is using catalogs as its search area definition.

the catalog have instructions about where can MEF look for

the compose-able parts (import and export definitions).

in short catalogs are actually a discovery instruction.


Out of the box catalogs

MEF is shipping with the following out of the box catalogs:

Code Snippet
  1. var typeCat = new TypeCatalog(typeof(IFoo));
  2. var asmCat = new AssemblyCatalog(typeof(Program).Assembly);
  3. var dirCat = new DirectoryCatalog("US", "*.dll");
  4. var aggCat = new AggregateCatalog(typeCat, asmCat, dirCat);
  5. var container = new CompositionContainer(aggCat);
  6. container.Compose(…);

  • TypeCatalog (line 1) define that specific types should includes in the discovery process.
  • DirectoryCatalog (line 2) instruct the discovery process to search for compose-able pars
    within specific assembly.
  • DirectoryCatalog (line 3) is the most common used catalog, which instruct MEF to
    search for compose-able parts within assemblies under specific directory using search pattern ("*.dll").
  • AggregateCatalog (line 4) is aggregation of different catalogs instances.
    this catalog enable to add and remove catalogs at runtime.



Silverlight (CTP 9) introduce new catalog named DeploymentCatalog which should replace the PackageCatalog.

my next post will discuss more on this topic (soon).

Silverlight is adding the PackageCatalog which is searching within assemblies which include

in the package.

the following snippet demonstrate the Silverlight PackageCatalog:

Code Snippet
  1. var catalogs = new PackageCatalog();
  2. catalogs.AddPackage(Package.Current);
  3. var container = new CompositionContainer(catalogs);
  4. container.Compose(…);

as you can see the PackageCatalog can include multiple packages.



The catalogs use to define the search boundary of the composition container discovery process.

different catalogs can be use for different boundary ranges.



each of the previous parts of this series contains samples which is using catalogs

you can explore the previous parts from the TOC.



kick it on

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



  1. Glenn Block2010/03/28 ב 11:34

    Hi Bnaya

    Loving this series, keep it up!

    We’ve updated our APIs now. PackageCatalog has been deprecated and is now replaced by a new DeploymentCatalog in SL4 which ships in the box. DC is also available in our latest codeplex drop for SL3.


  2. dor cohen2016/11/20 ב 12:48

    As soon as I detected this site I went on reddit to share some of the love with them.