Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC + MEF + MefContrib: Can't seem to get metadata from Exports
    primarykey
    data
    text
    <p>I'm using asp.net mvc3 with MEF + MEFContrib to load some services on my controllers. What's happening is that I can load the services - <code>IEnumerable&lt;IPublishService&gt; publishers</code> - with the <code>[ImportingConstructor]</code> but when I try to load the services with metadata - <code>Lazy&lt;IPublishService, IPluginMetaData&gt;[] publishers</code> - I get an empty array.</p> <p>Any thoughts on why? Thanks.</p> <p>My code:</p> <pre><code>public interface IPluginMetaData { string Name { get; } string Version { get; } } [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class PluginMetadataAttribute : ExportAttribute { public PluginMetadataAttribute(string name, string version) : base(typeof(IPluginMetaData)) { Name = name; Version = version; } public string Name { get; set; } public string Version { get; set; } } [Export(typeof(IPublishService))] [PluginMetadata("Default", "1.0.0.0")] public class SamplePublishService : IPublishService { } [ImportingConstructor] public HomeController(Lazy&lt;IPublishService, IPluginMetaData&gt;[] publisher /* Empty Array */ , IEnumerable&lt;IPublishService&gt; publishers /* Array with 1 service */) { } </code></pre> <p><strong>UPDATE (based on Daniel answer but still nothing)</strong></p> <pre><code>[MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class PluginMetadataAttribute : ExportAttribute { public PluginMetadataAttribute(string name, string version) : base(typeof(IPublishService)) { Name = name; Version = version; } public string Name { get; set; } public string Version { get; set; } } [PluginMetadata("Default", "1.0.0.0")] public class GoogleSampleGroupPublishService : IPublishService { } [ImportingConstructor] public HomeController([ImportManyAttribute]Lazy&lt;IPublishService, IPluginMetaData&gt;[] publisher) { } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload