MEF2 how does the catalogs work? Looks like it's been removed

4.2k views Asked by At

I can't find any good examples on MEF2.

I would like to create a plugin directory and use a directory catalog to load up Imports.

What I would like:

  1. No attributes. Use of the Configuration Builder with Conventions
  2. Plugin directory
  3. When a dll is added the application is aware of new Exports available.

Could I just use Castle Windsor for this?

2

There are 2 answers

0
Panos Rontogiannis On

The Conventions Model that was introduced with MEF2 is an alternative to the Attributed Model. Both models can coexist in an application. The Catalogs have a new constuctor that takes a ReflectionContext as an argument. The RegisrationBuilder is derived from this class. So you create a RegistrationBuilder, set it up and then create one or more catalogs using the new .ctors and passing it as a ReflectionContext.

Have a look at this series of articles introducing MEF2 features. Also have a look at this introductory article from CodeProject.

I haven't used Castle Winsdor so I can't comment on this.

0
Olly On

If you're referring to the new Windows Store version of MEF available on nuget, then the documentation states,

There is no catalog concept, nor composition batches, nor any “container hierarchy” or composition scoping APIs.

Sounds crazy to an MEF 1 developer, but the page explains the rationale well. However, you require:

  • When a dll is added the application is aware of new Exports available.

This is explicitly unavailable in MEF 2 (Win Store) version, since it doesn't support re-composition. For that you need the "full" MEF from the .NET Framework, in System.ComponentModel.Composition.