MEF with ImportMany and ExportMetadata

此生再无相见时 提交于 2019-12-05 00:50:28
Daniel Plaisted

It is probably not matching because your metadata interface doesn't match the metadata on the export. To match the sample export you've shown, your metadata interface should look like this:

public interface IMapMetaData
{
    int ID { get; }
}

To add metadata to a class derived from a class to which InheritedExport has been applied, you must apply the same InheritedExport attribute also to the derived class. Otherwise, metdata added to the derived class will be hidden and unavailable.

In other words, if you are using Lazy<T,TMetadata> to access applied metadata, and your imports are not being populated, it may mean you did not apply InheritedExport to all your derived classes.

If you instead apply Export instead of InheritedExport, you will end up with another instance of your part.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!