简体   繁体   中英

Custom prioritising the Parts in MEF

Hi I am using MEF and this is my case :

 [ImportMany]
 public IEnumerable<Lazy<IMyInterface>> correspondingParts { get; set; }

Now in correspondingParts, I get all the DLL's that is exported of type IMyInterface. But, the problem is like when I use

foreach(var parts in correspondingParts)
{
       // do something!
}

Now the correspondingParts contains DLL's which are sorted alphabetically by names. I need to be able to prioritise the DLL's.

Finally, this helped! The exporter needs to be able to create an ExportMetaData which can be used to get the priority later on. [ExportMetaData("Priority", 1)].

More info @ http://blogs.msdn.com/b/dsplaisted/archive/2010/04/01/overriding-mef-metadata.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM