开发者

MEF vs Unity import into view model

开发者 https://www.devze.com 2023-04-10 16:46 出处:网络
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?

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

精彩评论

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

关注公众号