Using DI in Activator? [message #938314] |
Tue, 09 October 2012 19:05 |
|
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 #939550 is a reply to message #938827] |
Wed, 10 October 2012 21:37 |
|
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 |
|
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 |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02528 seconds