I have the export specified in MEF preview 5
[ExportMetadata("Application", "CheckFolderApplication")]
[Export(typeof(ExtendedArtifactBase))]
public class CheckFolderArtifact2 : ExtendedArtifactBase
{ ...
Then I just want to import the data with the application metadata "CheckFolderApplication". To do this, I read the entire import, and then filtered out the result.
[Import(typeof(ExtendedApplicationBase))]
private ExportCollection<IApplication> _applications { get; set; }
public IApplication GetApplication(string applicationName)
{
return _applications.Single(a => a.GetExportedObject().Name == applicationName).GetExportedObject();
}
It seems very inefficient. What if I have thousands of plugins. Do I have to read them through MEF to get one of them with the correct metadata? If so, how do you cache the result?
Riiri source
share