简体   繁体   中英

ImportMany not working with Custom Metadata Attribute

I have created a custom Metadata Attribute for ImportMany in MEF, but ImportMany is always null.

[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class ,AllowMultiple = false)]
public class ModuleAttribute : ExportAttribute ,IModuleMetadata
{
    public ModuleAttribute(string contract)
        : base(typeof(IScreen))
    {
        Name = contract;
        Region = Region.Sidebar;
        IsVisible = true;
    }

    public string Name { get; set; }
    public string Module { get; set; }
    public Region Region { get; set; }
    public string DisplayName { get; set; }
    public bool IsVisible { get; set; }
    public string Description { get; set; }
    public short Order { get; set; }
    public Permissions Permissions { get; set; }
}

And here is how I export my class.

[Module("Stock" ,Module = "Stock" ,Order = 1 ,Permissions = Permissions.View)]
    internal sealed class StockWorkSpaceViewModel : Screen

where Screen is typeof(IScreen)

Here is my ImportMany.

[ImportMany]
public IEnumerable<Lazy<IScreen ,IModuleMetadata>> Modules { get; set; }

Can anyone predict, where I am going wrong.

  1. Check up the ComponnetContainer.ComposeParts
  2. Check up the export and import attribute which must be the same
  3. Check up the Customs Attribute and the interface you used in the lazy initialization. The property must be the same.That means the customs attribute class implement the lazy initialization implicit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM