Guice/peaberry/Sisu - or how to avoid service bindings in peaberry

80 views
Skip to first unread message

Gernot Kvas

unread,
Sep 26, 2012, 5:57:11 PM9/26/12
to guice...@googlegroups.com
Hi,

I'm quite new to Guice, so forgive my possibly naive question.

First, my current understanding: In basic Guice (without peaberry), you usually start off with a single injector and a static graph of modules, describing your bindings. All whats left is to use "@Inject" and you are good to go. For OSGi (I'm dealing with an OSGi environment), Guice provides a bridge classloader to work around the per-bundle classloaders, however it is left to the programmer to decide where to put one or more injectors (a single one, one per bundle, etc.). Let's pretend I've decided to use one injector per bundle, which doesn't play too well, as others found out too across plugin boundaries.

https://groups.google.com/d/topic/google-guice/w7gTINynRKs/discussion

I can work around that issue to some extend by using peaberry. I've still the injector per plugin scenario, but by exporting and importing services, I can inject a service exported in plugin A in plugin B. What really bugs me however is, and here I might have a wrong understanding, is that I have that boilerplate code in plugin B where I bind my service (I'd rather avoid keeping bindings in sync with Injects.)

Plugin A (Exports the service)

 @Inject
 
// the service can be controlled by the Export handle
 
Export<StockQuote> exportedQuote;
 
...
 
// the service is exported at injection time
 bind
(export(StockQuote.class)).toProvider(service(myQuoteImpl).export());

Plugin B (Consumes the service)


 @Inject
 
StockQuote quote;
 
...
 bind
(StockQuote.class).toProvider(service(StockQuote.class).single()); // Can this be avoided?

A played around a bit but couldn't come up with a simpler working solution. Am I missing something here? If not, this brings me to the topic of auto binding, where I found some entries in the Guice newsgroup:

https://groups.google.com/d/topic/google-guice/nMKHZOCLoVc/discussion

For me, that would work around my problem, but I also took a sneak peek at

http://www.eclipse.org/sisu/

which appears to have the right amount of magic out of the box.

I'd be glad if some can shed some light on this whole topic.

Cheers,

Gernot









Reply all
Reply to author
Forward
0 new messages