开发者

MEF vs Unity import into view model

When using unity you can import the container in the constructor of a view moder per say.

But how would I do import a MEF contai开发者_开发知识库ner into a view model to resolve instances?

Thanks


Generally, it is not a great idea to be passing round the container, as you end up using it as more of a service-location mechanism, but should you wish to do so, you would need to manually export the container, e.g.:

var container = new CompositionContainer(catalog);
container.ComposeExportedValue(container);

This will enable you to import it:

[Import]
public CompositionContainer Container { get; set; }

Or:

[ImportingConstructor]
public MyClass(CompositionContainer container) { }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜