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!
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: