Proper way to expose third party visual control in MEF

回眸只為那壹抹淺笑 提交于 2019-12-11 07:42:05

问题


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?


回答1:


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();
      }
   }
}

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




回答2:


What about wrapping the third party controls in "export" classes and then access this control through the wrapper?



来源:https://stackoverflow.com/questions/4017952/proper-way-to-expose-third-party-visual-control-in-mef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!