常用的两种去插件之间循环依赖 方法(Extension和OSGi)

一般来说想要去除Eclipse Plugin之间的循环依赖 ,这里介绍两种方法:
第一定义一个Extension Point,简单的就是在可以定义两个属性name, class;name用来指明实现这个扩展点的名称,class就是要实现这个扩展点要实现的公共接口.然后可以在其他Plugin中实现一个Extension Point.如果要实现这个实例就可以使用
IExtensionRegistry registry  =  Platform.getExtensionRegistry();
        elements 
=  registry.getConfigurationElementsFor(extension point ID);

的到所有的实现这个扩展点的Element再利用Object service = element.createExecutableExtension("class");就可以的得到你要的实例对象.
第二种方法就是利用Plugin种的BundleContext,这样的话首先在你要被引用的Plugin 的
public   void  start(BundleContext context)  throws  Exception  {
    
super.start(context);
    
//注册一个IWarehousePluginService接口的实例.
        context.registerService(IWarehousePluginService.class.getName(),
                
new WarehousePluginService(), null);
}

在这你要使用的地方用;
public  IWarehousePluginService getWarehouseService()  {
        ServiceReference reference 
= context
                .getServiceReference(IWarehousePluginService.
class.getName());
        
return (IWarehousePluginService) context.getService(reference);
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值