5

I would like to use Google Guice (2.0 or 3.0, does not matter) for my Netbeans Platform Project. My Project has several Netbeans Modules. I managed to use Guice in a single Netbeans Module, but now I want to Inject a Dependency from one NBModule to another. Is this possible? I googled a lot and searched the mailing lists of netbeans and guice, but it seems like noone ever tried this.

I do not want to use the Lookup API for this, because I really need Dependency Injection for better testing.

Has anyone experiences with that?

Edit: To be more specific: Can i Use the same Injector for all NBModules or do I have to create an Injector for every Module?

Dominik Obermaier
  • 5,610
  • 4
  • 34
  • 45
  • Don't know about Netbeans modules, but can't you use a singleton class with a Static variable with the injector that makes it available globaly? (BTW each JUnit test will need to initialize the injector again) – Kdeveloper Feb 19 '11 at 23:07

2 Answers2

3

I realize that this question is old, but since the subject is still relevant I decided to share my findings.

We successfully use Google Guice 3.0 in our Netbeans Platform project. This includes injecting dependencies across NBMs using one injector. The only issue we encountered was that Guice didn't recognize annotations in other NBMs, because they were loaded through other classloaders. See http://tkills.blogspot.com/2014/08/using-google-guice-in-netbeans-rcp.html for details.

Tarje
  • 146
  • 4
  • From your blog it sounds like you got everything to work by making a wrapper module for javax.inject.*. Was there anything that still didn't work after that? – Ryan Feb 11 '16 at 18:41
  • No, in our project, that was the only issue. – Tarje Apr 25 '16 at 11:36
0

I have not worked with Netbeans RCP, only with Eclipse RCP and with integration with Spring. We had to have separate Springs application context for every plugin, with one root context that was shared between all other plugins. So you would need similar thing, separate injectors for every modul. I am not sure but i thing Guice does not support concept of including one injector to another as parent injector.

Slavus
  • 1,168
  • 12
  • 20