The reason for the three exports is the fact that you derive your custom export metadata from the ExportAttribute
. This means that for each decoration a different export is taking place. Three decorations lead to three exports.
I'm not sure why you get all {Name,Version} pairs for each export.
To overcome the three exports you can update your custom attribute to derive from Attribute instead:
[MetadataAttribute, AttributeUsage (AttributeTargets.Class, AllowMultiple = true)]
public class ExportMetaFooAttribute : Attribute, IFooMeta
{
public string Name { get; private set; }
public string Version { get; private set; }
public ExportFooAttribute (string name, string version)
{
Name = name;
Version = version;
}
}
I have renamed it to ExportMetaFooAttribute
since it is not an export attribute but an export metadata attribute.
Then you change your Foo
class to:
[Export(typeof(IFoo))]
[ExportMetaFoo("Bar", "1.0")]
[ExportMetaFoo("Baz", "1.0")]
[ExportMetaFoo("Baz", "2.0")]
public class Foo : IFoo
{
public void Do ()
{}
}
As you can see now we need the extra ExportAttribute
to specify that this class needs to be exported.