I finally found the time to try out MEF and I really like it. But I'm a bit surprised that it does only support static composition, meaning all exports need to be attributed and compiled. There is no way to add an export through configuration.
So I tried to add dynamic exports by writing a ComposablePartCatalog, which makes it possible to add dynamic exports. But that is only possible if you know the ExportTypeIdentity, contract name and metadata of the imports beforehand. The problem here is
that ImportDefinition does not expose the metadata and only exposes the constraint property and IsConstraintSatisfiedBy() method. Even the ExportTypeIdentity is not exposed in the ImportDefinition class. But on the other hand, the complied constrained
of ImportDefinition relies on the Metadata property of the ExportDefinition class.
Short example why this could actually be useful: If, for example, I use the IMessageSender imports in my application and want to provide a default implementation for all imports of IMessageSender where no applicable exports exists, I'm unable to
do that because I don't even know which ExportTypeIdentity the ImportDefinition represents. By adding Metadata to ImportDefinition I would be able to do that and it would make ImportDefinition and ExportDefinition symetrical.
Actually I would even like to go a step further and use the contract name and metadata to configure my exports, so an import for IEmailSender and contract name "Sales" could use the same type as an import for IEmailSender and contract
name "HumanResources", but the actual instances would be configured differently (for example they would use different email addresses).