开发者

Importing dependencies using a class that inherits from Lazy<>

Can you import 开发者_开发百科using a class that inherits from Lazy rather than Lazy itself? I am exporting using a derivitive of ExportAttribute that contains metadata.

[FeatureExport(/* Feature Metadata Parameters */)]
public class Feature : IFeature
{
    // Feature Properties
}

public class FeatureReference : Lazy<IFeature, IFeatureMetadata>
{

}

public class Consumer
{
    [ImportMany]
    public IEnumerable<FeatureReference> FeatureReferences { get; set; }
}

Is this possible? Would it work? I could try it myself, but I'm in development so I don't actually have any code written.


No, it won't work I'm afraid. You would need to implement your own programming model extension (either a custom part/catalog or possibly via ReflectionModelServices) to make this work.

MEF would have to create the FeatureReference object in order to set it, and considering that FeatureReference might have any constructor imaginable, you can guess why this isn't supported.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜