What is the difference between the AddPart() and AddExport() in the composition batch class? When would I use one over the other?
What is the difference between the AddPart() and AddExport() in the composition batch class?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I was wondering about the same thing and unfortunately haven’t been able to find any documentation that describes the difference between AddPart, AddExport, (and AddExportedValue) concisely. Here is what I have learned so far:
A part in MEF terminology, is a component that provides capabilities (aka exports) and specifies dependencies (aka imports).
So when you call
batch.AddPart(something)then you are telling MEF that “something” is a component that may provide exports and depends on one or more imports.If you call
batch.AddExport(new Export("someExport", () => something))then you are telling MEF that “something” is a component that just provides exports without requiring any imports, i.e. MEF will ignore any[Import]annotations that may be specified in the “something” class.Internally AddExport actually calls AddPart, but prior to that it wraps the passed object in a “SingleExportComposablePart”, i.e. a ComposablePart returning an empty
IEnumerable<ImportDefinition>on a call toComposablePart.ImportDefinitions.