C# MEF Tutorial: Exports, Imports and Plugin Composition
The Managed Extensibility Framework composes components through declared contracts and discovery. Parts export capabilities and import dependencies, while the composition setup determines which parts are available. This differs from simply creating a class by name: missing, ambiguous or incompatible contracts affect whether the application can assemble the intended plugin graph.
Here's a popular C# MEF video — watch it, then summarize it with one click. Or paste any other YouTube link below.
— or paste your own YouTube link —
Want to keep the key points from a YouTube video? Paste the link below to turn it into structured notes.
Why Use C# MEF Tutorial: Exports, Imports and Plugin Composition
- Declare exported plugin capabilities
- Match imports to available contracts
- Control the discovery catalog
- Diagnose unsatisfied composition dependencies
- Separate plugin discovery from business execution
Frequently Asked Questions
Does an export attribute load a plugin by itself?
The export supplies metadata for a composition system to discover. The host still needs an appropriate discovery and composition setup; a decorated class outside that scope does not automatically join the running application.
How is MEF different from ordinary dependency injection?
Both connect dependencies, but MEF emphasizes discoverable parts and composition contracts. Container registration alone does not describe every plugin discovery or metadata-selection workflow, so select the model that fits the extensibility boundary.
Why can composition fail with an import error?
An import can lack a matching export, encounter multiple unexpected matches or depend on another unresolved part. Inspect the entire contract chain rather than assuming the first named class is the only cause.
What should plugin metadata describe?
Metadata can communicate selection information such as a supported capability without forcing immediate plugin behavior. Keep it stable and meaningful so the host can choose suitable parts before relying on their implementation details.
Can every MEF example use the same package and API?
Different MEF-related implementations and framework generations expose different facilities. Identify the demonstrated composition library and target before mixing catalog, attribute or lifetime code from unrelated versions into one application.