e4 rcp @inject 注入自己的对象

package redisclient.context.func;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IContextFunction;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.osgi.service.component.annotations.Component;

import redisclient.context.bean.Bean;

@Component(name="redis.services.bean", service=IContextFunction.class,
property="service.context.key=redisclient.context.bean.Bean")
public class TestContextFunction extends ContextFunction {
	@Override
	public Object compute(IEclipseContext context, String contextKey) {
		
		Bean bean =  ContextInjectionFactory.make(Bean.class, context);
		
		 MApplication app = context.get(MApplication.class);
	     IEclipseContext appCtx = app.getContext();
	     appCtx.set(Bean.class, bean);
		
		return bean;
	}

}

e4 中实现@inject  Bean bean 需要实现contextFunction类,需要注意的是service.context.key='类的全路径',如果注解不生效,添加配置文件,同时在manifest中加入Service-Component: OSGI-INF/service.xml



   
    
   
      
   

 

    

 

转载于:https://my.oschina.net/zhenghuazhi/blog/1335052

你可能感兴趣的:(e4 rcp @inject 注入自己的对象)