在MEF中公开第三方可视控件的正确方法 [英] Proper way to expose third party visual control in MEF

查看:75
本文介绍了在MEF中公开第三方可视控件的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行此操作的正确方法是什么? 假设我们的项目中有一些第三方库,我们需要提供对某些密封控件的访问. 将使用MEF创建新的小部件并将其添加到应用程序中,它们应该能够从核心应用程序中导入一些控件. 那么如何正确导出这些控件呢?

What is the proper way to do that? Let's say we have some third party library in our project and we need to provide an access to some controls which are sealed. New widgets will be created and added to the application using MEF and they should be able to import some controls from the core application. So how to export those controls properly?

推荐答案

如果您不能修改原始类(例如ThirdPartyComponent),则可以通过另一个类(例如ThirdPartyComponentExporter)上的属性进行导出:

If you cannot modify the original class (e.g. ThirdPartyComponent), then you can do the export via a property on another class (e.g. ThirdPartyComponentExporter):

public class ThirdPartyComponentExporter
{
   [Export(typeof(ThirdPartyComponent))]
   public ThirdPartyComponent Foo
   {
      get
      {
         return new ThirdPartyComponent();
      }
   }
}

对于视觉控件,您可能必须使用CreationPolicy.NonShared来防止MEF在不同位置重用同一实例.

For visual controls, you may have to use CreationPolicy.NonShared to prevent MEF from reusing the same instance in different locations.

这篇关于在MEF中公开第三方可视控件的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆