Default exportable part

Jan 6, 2010 at 8:38 AM

Hi all,

I would like to register one class as the default exportable part with MEF as below:

// This class is registered firstly
class Class1: IClass

// This class is registered secondly
class Class2: IClass

// Resolves IClass Instance
IClass myClass = container.GetExportedValue<IClass>();
// myClass will get an instance of Class2

Could you please show me how I can realize this. With Prism, the Resolve method always returns an instance of the latest registerd type.

Thank you so much!

Jan 6, 2010 at 9:05 AM

Hi Steven

Prism defers to the underlying IoC container for determining which instance will be returned. In the case of Unity which Prism uses by default, it gives that behavior, but that is not fixed.

With regards to MEF there's no "default part" per se as there is no central configuration. A part that is default in one system, might not be in another. We do have a way to address defaults though through using ExportProviders. If you check this post, you will see how to do this: