Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Inject IEclipseContext in Service-Component
Inject IEclipseContext in Service-Component [message #1709161] Thu, 24 September 2015 14:34 Go to next message
Thibault Pensec is currently offline Thibault PensecFriend
Messages: 18
Registered: September 2015
Location: Nice (France)
Junior Member

I need to use DI in the activation method of an OSGI Service-Component. To resume the situation, see bellow my actual configuration.

First of all, I inject a custom context bean in the IEclipseContext :

public class LifeCycleManager {
	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);

Next I declare a Service-Component in the META-INF/MANIFEST.MF of my service plug-in :

Bundle-Name: Service
 javax. inject,
 org.eclipse.e4.ui. model.workbench,
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="">
   <implementation class=""/>
      <provide interface=""/>

And finally, the implementation code of my component where I need the retrieve my MCustomContext :

public class MyServiceComponent implements MyService {
	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 Cool
Re: Inject IEclipseContext in Service-Component [message #1709166 is a reply to message #1709161] Thu, 24 September 2015 14:52 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
Registered: July 2012
Senior Member
You can not use DI in an OSGi service. Dependent on your needs you either specify a referenced service if you want to stay in the OSGi world, or try to use a context function which supports access to the IEclipseContext.
Previous Topic:How to port code using E3 ShowViewDialog to E4?
Next Topic:Initial enable status of Dynamic Menu Contribution not properly determined with sub-elements
Goto Forum:

Current Time: Tue Sep 25 09:49:36 GMT 2018

Powered by FUDForum. Page generated in 0.02442 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top