Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Using DI in Activator?
Using DI in Activator? [message #938314] Tue, 09 October 2012 19:05 Go to next message
Markus Oley is currently offline Markus OleyFriend
Messages: 304
Registered: July 2009
Location: Germany
Senior Member
Hi,

I have a rcp application using e4 and want to use di anytime starting stopping a plugin.
In Eclipse 3.x I put this implementations to Activator#start() and stop().
Now I want to instantiate a class wih DI using the current IEclipseContext.

Is this possible and if yes, how ?
If not possible, were could I put my implementations to? I need this implements in more than one plugin, so the lifecycleURI is not the right place.


This is my last problem migrating my appliaction to e4 :-)-
E4 rocks. I guess I have removed 10-20% of my old code.

Best regards
Markus

[Updated on: Tue, 09 October 2012 19:06]

Report message to a moderator

Re: Using DI in Activator? [message #938827 is a reply to message #938314] Wed, 10 October 2012 07:26 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
There's no way of doing this in your activator, you can get the global
IEclipseContext through the EclipseContextFactory this not a good idea.

If you want to create stuff lazy when it is needed. You could contribute
an IContextFunction through DS, or use an Addon.

Tom

Am 09.10.12 21:05, schrieb Markus Oley:
> Hi,
> I have a rcp application using e4 and want to use di anytime starting
> stopping a plugin. In Eclipse 3.x I put this implementations to
> Activator#start() and stop(). Now I want to instantiate a class wih DI
> using the current IEclipseContext.
> Is this possible and if yes, how ? If not posssible, were could I put my
> implementations to? I need this implements in more than one plugin, so
> the lifecycleURI is not the right place.
>
>
> This is my last problem migrating my appliaction to e4 :-)- E4 rocks. I
> guess I have removed 10-20% of my old code.
>
> Best regards
> Markus
>
Re: Using DI in Activator? [message #939550 is a reply to message #938827] Wed, 10 October 2012 21:37 Go to previous messageGo to next message
Markus Oley is currently offline Markus OleyFriend
Messages: 304
Registered: July 2009
Location: Germany
Senior Member
Hi Thomas,

thanks for your answer,

I have reimplemented my case the following way:

In my Activator I register classnames at start and deregister classnames at stopping bundle. In the handler I use these registered things,
I want to inject them knowing the classname.
How can I create instances of the classes without @Inject?
I tried IEclipseContext, but got null although I added an annotation @Creatable.

Can you give me some example or tutorial I can take a look?

Regards
Markus

Re: Using DI in Activator? [message #939557 is a reply to message #939550] Wed, 10 October 2012 21:45 Go to previous messageGo to next message
Markus Oley is currently offline Markus OleyFriend
Messages: 304
Registered: July 2009
Location: Germany
Senior Member
OK, by debugging how E4 injects other things I found the solution:

public static Collection <IUserTab> createRegisteredUsertabs (IEclipseContext context) {
  Collection <IUserTab> usertabInstances = new ArrayList<IUserTab>();
		
  for (Class<? extends IUserTab> nextTab: usertabs) {
	IUserTab userTab = ContextInjectionFactory.make(nextTab, context);
	if (userTab == null)
 	  throw new IllegalStateException("Could not find usertab with class " + nextTab.getName());
			
	usertabInstances.add(userTab);
  }
	
  return usertabInstances;
}


Is this a solution that's OK from E4s point of view? Or is there a better way?
Re: Using DI in Activator? [message #941220 is a reply to message #939557] Fri, 12 October 2012 09:59 Go to previous messageGo to next message
Eclipse UserFriend
I'm not sure what you are trying to accomplish so I can't tell if there's a better way in e4. However the general idea is that the Eclipse DI stuff is better handled above the Activator level. Activators and bundle contexts are too low for injecting things from.
Re: Using DI in Activator? [message #981462 is a reply to message #941220] Mon, 12 November 2012 12:35 Go to previous message
Markus Oley is currently offline Markus OleyFriend
Messages: 304
Registered: July 2009
Location: Germany
Senior Member
OK, thank you.

I've solved my scenario with an extension point, works
Previous Topic:Proper naming of an eclipse component
Next Topic:Any chance to use Eclipse's own flyout menus?
Goto Forum:
  


Current Time: Thu Mar 28 10:00:05 GMT 2024

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

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

Back to the top