GetExported<> & ComposeParts

Aug 12, 2010 at 1:05 PM

Hi Everyone,

I don't understand where to use below methods while composing parts in MEF:

1. GetExports<> or GetExportedValue<> - Do I need to have Import while using GetExportValue<> method. - I tried out this and its working without Import then why one should need Import properties.

2. ComposeParts() - As I understand, this is satisfying all defined Imports to Exports.. but more clarification would be helpful.

3. ComposeExportedValues() - what is this? and in which scenario I should go for this.

In case of designing application which is already using PRISM (Composite WPF) framework , which of the above exporting functionality I should use.

- Thanks

Aug 12, 2010 at 5:03 PM
Edited Aug 12, 2010 at 5:04 PM
  1. GetExports returns a collection of exports (with metadata), it's the equivalent of the ImportMany attribute. GetExportedValue gets the immediate value, you don't get to see metadata and that's practical if you don't need to see the metadata.
  2. ComposeParts is used to add a part to the container, it does satisfy imports but so does the SatisfyImportsOnce method which I suggest you use if you just want to fill your import definitions.
  3. ComposeExportedValue method is just a convenient extension method which I believe does the exact same thing as ComposeParts, or eventually it ends up calling that method with some arguments.

The above are all applicable but for different scenarios, and I've tried to give an example for each one. The ComposeParts is probably a bit tricker to get, because most often you don't use it directly. If you have an object and you want to expose that particular object in a container, you can use ComposeParts to add that instance. If you later satisfy an import with that object is it the same instance. That can be helpful if you need to isolate some runtime context thing.

Aug 13, 2010 at 4:11 AM

Hi Leideqre,

Thanks for your prompt reply with very good information.

I am trying to get Metadata using GetExports<> method but I was not able to get Metadata out of it. Currently I am using Lazy<IFactory, IFactoryMetada> to get Metadata of IFactory implementation classes.

Can you please provide some example/small demo to understand usage of GetExports<> method.

- Thanks again.

Aug 13, 2010 at 4:43 AM

Hi Leideqre,

I have tried GetExports<IFactory,IFactoryMetadata> and its working ... Cool :)

If you can help me out on deciding where to use ComposeParts & GetExports()... and How MEF returns Exports from GetExports() without knowing its Imports.

- Thanks

Aug 14, 2010 at 12:32 PM
Edited Aug 15, 2010 at 9:51 PM

That's a lot of stuff to cover.

There are already good and thorough discussions about what you ask, you can search and browse the forum for that information or ask a specific question.

The best I can do is to ask you to be very specific, that way it's easier for me (and others) to provide correct answers (if there is such a thing).