Hi,
I need to use DI in the activation method of an OSGI Service-Component. To resume the situation, see bellow my actual configuration.
APPLICATION PLUGIN (com.my.app)
First of all, I inject a custom context bean in the IEclipseContext :
public class LifeCycleManager {
@PostContextCreate
public void postContextCreate(IEclipseContext context) {
//
// Initialize the Custom Context and set it into the Eclipse Context
//
final MCustomContext customContext = PersistenceUtils.load(MCustomContext.class);
context.set(MCustomContext.class, customContext);
}
}
SERVICE PLUGIN (com.my.service)
Next I declare a Service-Component in the META-INF/MANIFEST.MF of my service plug-in :
Bundle-Name: Service
Bundle-SymbolicName: com.my.servicer;singleton:=true
Require-Bundle: com.my.app,
javax. inject,
org.apache.log4j,
org.eclipse.e4.core.di,
org.eclipse.e4.core.services,
org.eclipse.e4.ui. model.workbench,
org.eclipse.osgi.services
Service-Component: OSGI-INF/mycomponent.xml
Bundle-ActivationPolicy: lazy
Here the content OSGI-INF/mycomponent.xml :
<?xml version="1.0" encoding="UTF-8"?>
<scr:component activate="activate" name="com.my.service">
<implementation class="com.my.internal.MyServiceComponent"/>
<service>
<provide interface="com.my.service.MyService"/>
</service>
</scr:component>
And finally, the implementation code of my component where I need the retrieve my MCustomContext :
public class MyServiceComponent implements MyService {
@Inject
MCustomContext customContext;
/**
* Activation method
*/
protected void activate(ComponentContext context) {
// this.customContext == null
}
}
Is it the right solution ? Or is it simply impossible ?
Need your help