This project has moved. For the latest updates, please go here.

Question about Import/Export [closed]

Apr 10, 2011 at 5:16 PM

I would like to ask if I declared some Export objects by name and type can I import all of them by using only type ? So later I could call:


For exapmle export:

    public class Job : IJob 

 and import:


    IEnumerable<Lazy<IJobIJobName>> Jobs;
Apr 11, 2011 at 5:46 AM

So if the name is metadata (as ExportMetadata("Name", "PrintSomething")) then yes you can import all of them, however if you give it a specific contract name like you did in your sample "tempJob" then no you cannot. Importing and Exporting is keyed on a contract name and so that contract name needs to be the same if order to import all of them.

Apr 11, 2011 at 8:18 AM

You can put multiple export statements on your class:


[Export("tempJob", typeof(IJob))]
[ExportMetadata("Name", "PrintSomething")]
public class Job : IJob


Apr 11, 2011 at 8:31 AM
Edited Apr 11, 2011 at 8:34 AM

Now I have something like this, and I think it works how I have expected. Thanks.

    [Export("Job1.Job1, Job1",typeof(IJob))]