Exporting by type and contract - ImportMany does not work as expected

By : katit
Source: Stackoverflow.com
Question!

If you look at this question's answer with most upvotes - this is what I'm trying to do: C# MEF: Exporting multiple objects of one type, and Importing specific ones

My code:

[Export("MainTripWizardController", typeof(IWizardController))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class MainTripWizardController : BaseViewModel, IWizardController
    {

I used contract name so I can import it in one specific place (and it works)

[Import("MainTripWizardController")]
        public IWizardController TripWizardController { get; set; }

But I also need access to all 'IWizardController' in other place where I will check if needed type exported:

[ImportMany(typeof(IWizardController))]
        public IEnumerable<IWizardController> WizardControllers { get; set; }

And this doesn't work. If I remove contract name string in Export - I will get it in my bottom sample. But I need to be able to import this class either by interface in enumerator or by contract name if I want specific copy. Any advice?

By : katit


This video can help you solving your question :)
By: admin