The Managed Extensibility Framework (MEF) is designed to allow open-ended extensibility. It is easy to define a contract and load extensions which satisfy the contract. This is accomplished with a collection import, which can look like this: [ImportMany] public IPlugin[] Plugins { get; set; } Extensions may need to be ordered or prioritized Often, the importer will need a way to sort or prioritize the imported extensions. If the extensions are displayed in a menu, the importer may want to control what order they appear in. Or there may be multiple extensions which can be used, and the importer needs to choose the “best” one which can handle a given item. For example, if extensions are used to provide UI controls for editing fields, there may be a generic editor which can edit all field types but only uses a simple textbox, and a specialized editor which only works on enums but provides a dropdown box for editing. Both of these extensions could be used to edit an enum, but it is better to use the more specialized one. Defining MEF metadata on an export One way to represent the priority of an extension is with MEF metadata. The exporter can add metadata using the ExportMetadataAttribute like this: [Export(typeof(IPlugin))] [ExportMetadata("Name", "PluginA")] [ExportMetadata("Priority", 1)] public class PluginA : IPlugin { /* ..
Here is the original:
Overriding MEF Metadata