Rock3rRullz
Rock3rRullz

Reputation: 465

MEF Filter ImportMany

Let's say that I have the following 3 classes:

[Export("Settings",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings1Vm {}

[Export("Settings",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings2Vm {}

[Export("Settings",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings3Vm {}

If is possible for example to do this:

[Import]
private ISettingsItem SettingEntry{ get; set; }

But in a way that this import only takes the export of the Settings2VM class?

Regards

Upvotes: 0

Views: 297

Answers (1)

Rock3rRullz
Rock3rRullz

Reputation: 465

It seems that the solution was:

[Export("Settings",typeof(ISettingsItem)]
[Export("Settings2Vm ",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings2Vm {}

[Import("Settings2Vm ", typeof(ISettingsItemVM))]
private Settings2Vm SettingEntry{ get; set; }

This way I will always have the same instance.

Upvotes: 1

Related Questions