This project has moved and is read-only. For the latest updates, please go here.

MEF thread safety

Jun 19, 2016 at 3:42 PM
Edited Jun 19, 2016 at 3:42 PM
The export providers like:
  • CompositionContainer
  • ComposablePartExportProvider
  • CatalogExportProvider
have dedicated constructors that accept parameter (bool isThreadSafe) indicating that it should be "true if export provider must be thread-safe; otherwise, false.".

We know that even if we specify "true" - above classes won't be thread-safe for operations that causes recomposition (e.g. executing composition or exports change in the uderlying catalog).

Does it still means that if we provide synchronization for operations causing recompositon - other operations will be guaranteed to be thread safe? (assuming isThreadSafe=true)

Other words:
  • we set isThreadSafe=true
  • we put lock on operations causing recomposition (so that Compose(...), Catalogs.Add(...) are synchronized)
  • we do not synchronize GetExports operations or access to the exported objects via Lazy<> imports
Does it is still thread-safe?