MEF discovery without attribute

Nov 18, 2008 at 8:25 PM
Hi
  I am trying a following scenario but having lot of difficulty to understand how to do it. I have a extended assembly which has many types sorrounded with Export Attributes.  eg [Export(typeA)]class A{} , [Export(typeB)]class B{}.
In my application I have a use case where I don;t know what type to import at compile type. So I cannot use something like [Import(typeA or typeB)]. Is it possible to use MEF to discover these types at runtime without the Import attribute.
If so could you please let me know how can i do it. I saw the link on POCO with MEF but looks like some of the interfaces used in are deprecated.

Thanks
Mark
Coordinator
Nov 18, 2008 at 11:13 PM
You can have both types implement a shared interface, and then export that interface.  If you don't want to do that, you can use a string as the contract and import into an object.  It would look something like this:

// Export side
[Export("MyContractName")]
public class MyClas { ... }

// Import side
[Import("MyContractName")]
public object MyImport { get; set; }

Thanks,
Daniel