views:

139

answers:

1

Hi guys, I'm studying MEF and I'm not able to resolve a problem.

I have a main application, called MainMEF, and a simple module, called SimpleModule. This one consists of a single UserControl which is loaded dinamically.

When MainMEF starts up, I would be able to pass to the module a reference to main application contained into MainMEF.

How could I fix this? Thanks in advance.

+3  A: 

Lots of questions regarding this already. You could pass it after initialisation using a property: http://stackoverflow.com/questions/2939867/how-do-i-populate-a-mef-plugin-with-data-that-is-not-hard-coded-into-the-assembly

Or use MEF constructor parameters: http://stackoverflow.com/questions/2941158/mef-constructor-parameters-with-multiple-constructors

The export looks something like this:

[Export(typeof(ITest))]
class Test : ITest 
{
    void Test() 
    {  }

    [ImportingConstructor] //<- This is the key bit here
    void Test(object parameter) 
    {  }
}

Then when composing your catalog do this:

catalog.ComposeExportedValue( /* parameter here */);
catalog.ComposeParts(this);
Tim
Thank you for your reply. Very helpful. Could you explain me these lines with more code? Take into account catalog.###catalog.ComposeExportedValue( /* parameter here */);catalog.ComposeParts(this);###What kind of type does it belong to?
Flex_Addicted