Why use MEF metadata instead of just extending the interface to include the metadata?
So intead of using ExportMetadata attribute, why not just extend the interface inst开发者_如何转开发ead?
if you import Lazy<> stuff via MEF you can look into the metadata without instantiate your object.
Good question. I think that extending the interface is the correct thing to do whenever you have the option. It much better communicates intent.
However, we may need more fine-grained control over interfaces that we don't own. In those cases we can use ExportMetadata
as a substitute.
In my opinion you should only use ExportMetadata
when there is no other option available to you.
精彩评论