Importing Part problem

May 3, 2010 at 5:09 PM

Hi All,

I'm wondering if someone can help me out here. I've got an application that does something like:

[InheritedExport]
public interface IMySharedObject
{
}

public class MySharedObject : IMySharedObject
{
}

[Import]
IMySharedObject myObj;

// on import
myObj.Initialize();

//later...
IMySharedObject myObj2 = container.GetExportedValue<IMySharedObject>();
 
For Some reason the myObj2 creates a new instance (so not initialized). 
It was my understanding that exported objects defaulted to shared so it should already be initialized.
If I do another [Import] I get the original object, why not with getExportedValue?
 
please Help...
Deane
May 3, 2010 at 5:39 PM
Edited May 3, 2010 at 5:39 PM

Well I figured this out.

In case anyone else is interested, the problem was that I was initializing the CompositionHost with my AggregateCatalog, not my CompositionContainer.

So I was getting a shared object per container, exactly like you are supposed to. :)

May 3, 2010 at 8:43 PM

That'll do it :-)

Glad you figured it out. Might be a good gotcha to blog about....

Glenn