Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Dependency Injection in eclipse plugins (not RCP apps)
Dependency Injection in eclipse plugins (not RCP apps) [message #1033388] Thu, 04 April 2013 07:28 Go to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
I'm struggling to understand how to use Dependency Injection features in regular eclipse plugins. All of the tutorials out there only mention how to do this in RCP apps, and i seem to misunderstand something fundamentally here.

Here's an example:

1. I have some service POJO class, annotated with @Creatable
2. I want to inject this service into an org.eclipse.core.runtime.jobs.Job, using the @Inject annotation

When i only use these 2 annotations, no service is being injected, and the service is null at runtime.

However, when i implicitly call "ContextInjectionFactory.inject(this, context);" inside the constructor of the Job class, the service is being injected.

Is this the regular way to do this in eclipse plugins? I would have assumed that the Job subclasses are managed by the eclipse context, hence i don't need to manually inject the dependencies.

Any info on that would be greatly appreciated.

Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1033399 is a reply to message #1033388] Thu, 04 April 2013 07:41 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
DI only works if the instance of the object is created using CIF#make

Tom

On 04.04.13 09:28, Robert Gruendler wrote:
> I'm struggling to understand how to use Dependency Injection features in
> regular eclipse plugins. All of the tutorials out there only mention how
> to do this in RCP apps, and i seem to misunderstand something
> fundamentally here.
>
> Here's an example:
>
> 1. I have some service POJO class, annotated with @Creatable
> 2. I want to inject this service into an
> org.eclipse.core.runtime.jobs.Job, using the @Inject annotation
>
> When i only use these 2 annotations, no service is being injected, and
> the service is null at runtime.
>
> However, when i implicitly call "ContextInjectionFactory.inject(this,
> context);" inside the constructor of the Job class, the service is being
> injected.
>
> Is this the regular way to do this in eclipse plugins? I would have
> assumed that the Job subclasses are managed by the eclipse context,
> hence i don't need to manually inject the dependencies.
>
> Any info on that would be greatly appreciated.
>
>
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1033403 is a reply to message #1033388] Thu, 04 April 2013 07:47 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Well, how are you creating the Job? If you are creating the Job with "new", than how should the framework know that something needs to be injected?

You could also create your Job by using "ContextInjectionFactory.make()". Then the injection should happen.
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1033478 is a reply to message #1033388] Thu, 04 April 2013 09:11 Go to previous messageGo to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
thanks for your tips, makes totally sense.

So just to make sure: For regular eclipse plugins, the only thing to make DI work is to use the ContextInjectionFactory API properly, like you mentioned above.

No need for any additional configuration in the plugin.xml or somewhere else?

Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1033883 is a reply to message #1033388] Thu, 04 April 2013 19:00 Go to previous messageGo to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
Just had a case where i'm not creating an instance of a class myself using "new", but the class is created by eclipse, namely a PreferencePage.

The PreferencePage is defined in my plugin.xml, and using @Inject for the class attributes results in a null value for the property instead of the dependency being injected.

Any idea how to handle this case properly?


Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1033946 is a reply to message #1033883] Thu, 04 April 2013 21:08 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Old stuff is not created through DI, plugin.xml stuff is created through
the Equinox-Extension-Registry which does NOT even know about our DI
framework.

Tom

On 04.04.13 21:00, Robert Gruendler wrote:
> Just had a case where i'm not creating an instance of a class myself
> using "new", but the class is created by eclipse, namely a PreferencePage.
> The PreferencePage is defined in my plugin.xml, and using @Inject for
> the class attributes results in a null value for the property instead of
> the dependency being injected.
>
> Any idea how to handle this case properly?
>
>
>
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1034274 is a reply to message #1033388] Fri, 05 April 2013 08:28 Go to previous messageGo to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
i see. But when you refer to "old stuff": This is what you get when you create a new plugin project in PDT (Kepler).

Does this mean creating a new plugin project in Kepler results in starting with a legacy plugin? How does plugin development work with the "new stuff" ??

This is pretty confusing. Most of the resources out there only talk about eclipse 4 in regard to RCP development, and starting a new plugin project in Kepler apparently results in a plugin skeleton wich uses legacy code.

Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1034282 is a reply to message #1034274] Fri, 05 April 2013 08:39 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
It really depends on what you want to develop. What is the new plugin
you are trying to provide? An editor, a view?

The pure e4 stuff currently lacks e.g. informations needed to define
editors so you simply can't define an editor in pure e4 sense. So IMHO
your best bet if you want to use the new DI stuff is that you use the so
called e4 bridge (simply search for it in google).

It brings the DI stuff to your 3.x development story. There's bug 376486
which request allowing to contribute to the IDE like you contribute to
an RCP app but this is planned for Luna only (to some extend you can use
already today and there are examples like the live-model-editor).

Tom

On 05.04.13 10:28, Robert Gruendler wrote:
> i see. But when you refer to "old stuff": This is what you get when you
> create a new plugin project in PDT (Kepler).
>
> Does this mean creating a new plugin project in Kepler results in
> starting with a legacy plugin? How does plugin development work with
> the "new stuff" ??
>
> This is pretty confusing. Most of the resources out there only talk
> about eclipse 4 in regard to RCP development, and starting a new plugin
> project in Kepler apparently results in a plugin skeleton wich uses
> legacy code.
>
>
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1034473 is a reply to message #1033388] Fri, 05 April 2013 13:23 Go to previous messageGo to next message
Robert Gruendler is currently offline Robert GruendlerFriend
Messages: 66
Registered: June 2011
Member
great, thanks a lot for your tips!
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1062123 is a reply to message #1034473] Thu, 06 June 2013 06:41 Go to previous messageGo to next message
Sumit Singh is currently offline Sumit SinghFriend
Messages: 141
Registered: October 2012
Location: Bangalore
Senior Member

Thanks for great Answer. I also had same problem.
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1754652 is a reply to message #1033388] Tue, 21 February 2017 10:26 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 307
Registered: July 2009
Location: Germany
Senior Member
Hi all,

I am digging up this old, dusty thread, because I had a discussion the other day about whether we could start migrating to e4. The problem for us is that we do not develop an RCP but an IDE. So we do not only have views, editors, commands, menu items and the like, but also project natures, builders, common navigator extensions, decorators, property pages etc. etc..

It is clear that for the former stuff, we can create e4-injected POJOs and enhance the application model. But for the latter, which Tom called "old stuff" above Wink, we do not see a clear strategy or best practice on how to do it.

What is/was the thought behind e4 concerning those topics? Was e4 only planned as a an overhaul of the UI part and having all those nice things like DI, the event broker etc. only there?

Because, for any further development of Eclipse and its plug-ins it seems that we are stuck in some kind of middle world between the e4-ified UI world and the legacy-e3 "old stuff" world. So people do not have to learn e3 or e4; they need to learn both and understand when to use either.

So, short questions:
- are there any plans on how Eclipse will move forward regarding the "old stuff"?
- are there any best practices on how to deal with non-UI "old" stuff (builders, natures, adapter factories, team providers, ...) so E4 DI can be used there as well (and because it is not possible out of the box: are there best practices how to enable this with some boiler plate code)?

Any pointers (maybe even to existing documentation I might have missed) are very welcome.

Cheers,
Stefan



Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1755393 is a reply to message #1754652] Thu, 02 March 2017 18:30 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
builders. natures, adapter-framework are things from core layer so they are unaffected from the e4 transition, what you miss
* is an editor framework because this stuff is found in layers who depend on the compat story - for e(fx)clipse i worked on a editor framework (I once also created a prototype for swt - https://github.com/BestSolution-at/code-swt)
* for preferences there is IIRC some work done but I don't know the state
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1755423 is a reply to message #1755393] Fri, 03 March 2017 08:50 Go to previous messageGo to next message
Stefan Winkler is currently offline Stefan WinklerFriend
Messages: 307
Registered: July 2009
Location: Germany
Senior Member
Hi Tom,

I think I understand the background (E4 = RCP/application framework, strive to be (more) independent of SWT ...).
But on the other hand, E4 also introduces a lot more interesting and modern technologies (DI, EventBus, ...) and not to have them in the "core logic" feels like a loss.
This is where my question pointed: Currently new developers have to learn about extension points, OSGi services, and E4 application model enhancements via fragments.
And only in the latter, we are able to use e4 DI. So I have to train new developers (who develop an IDE, not plain RCP) that there is shiny new E4, but also extension points. I have to train them about when to use what and that at the one instance they can (and should) use E4 DI, but in the other instances they can't (or need to add bridge logic* to be able to).

*) and the other question was: are there best practices on how to do it, or should it not be done and we should stick to the old ways?

Best
Stefan
Re: Dependency Injection in eclipse plugins (not RCP apps) [message #1755426 is a reply to message #1755423] Fri, 03 March 2017 09:12 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Well the main thing is apparently that the IDE is still based on Eclipse 3.x and running on the compat layer. In my migration attempts I always try to work around extension points and find a way to use OSGi DS as replacement. While extension points where good in the past (I don't want to blame them or say they are bad), there are better possibilities nowadays with OSGi DS (yes I am a fan of that technology).

For preferences I created some small solution based on OSGi DS a while ago, so I can get rid of these extension points also: https://github.com/fipro78/e4-preferences
With Oxygen it will be possible to provide programmatical core expressions instead of the extension points versions (think they are coming with M6).

I'm not sure about everything and all the states and plans, but in my opinion in the long term there should be replacements for all extension points. But that is just my opinion.
Previous Topic:Eclipse 4 - 3.x Bridge no available
Next Topic:Reproduce IElementUpdater behaviour in E4
Goto Forum:
  


Current Time: Fri Apr 19 23:55:14 GMT 2024

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

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

Back to the top