This project has moved and is read-only. For the latest updates, please go here.

MEF discovery without attribute

Nov 18, 2008 at 9:25 PM
  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.

Nov 19, 2008 at 12:13 AM
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
public class MyClas { ... }

// Import side
public object MyImport { get; set; }