Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Equinox and Guice pattern
Equinox and Guice pattern [message #671606] Wed, 18 May 2011 13:03 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

I am looking for a pattern on how to use Guice in an eclipse RCP
application. I expose services now by creating an Injector in the plugin
activator something like this:


public void start(BundleContext bundleContext) throws Exception {
DataActivator.context = bundleContext;
injector = Guice.createInjector(new CDODataServiceModule());
}


The guice Module, will create the object graph, as common with Guice.
In a consumer plugin, I would do a field injection to get an instance of
a class.


@Inject
private IDataService dService;

DataActivator.getInjector().injectMembers(this);

As such this works and my dService is instantiated, but I am aware Guice
wasn't intended to be used as such, but rather have a bootstrap class
which would inject all dependencies in the whole application. This
however doesn't fit in the concept of bundles which form the application
and can be started at any given time.

Perhaps, there is a pattern I am overlooking and should be used? (I Have
heard of http://code.google.com/p/peaberry/ , anyone any experience with
this?).

I also wonder how Guice relates to OSGI DS?

Thanks
Christophe
Re: Equinox and Guice pattern [message #689226 is a reply to message #671606] Mon, 27 June 2011 07:43 Go to previous message
Mike Rumpf is currently offline Mike RumpfFriend
Messages: 47
Registered: July 2009
Member
Personally I think there is no need for Guice in an OSGi-environment since the ds (declarative services) provide you with a powerful, easy-to-use framework for dependency injection. Of course it's also a matter of taste but with ds you declare your services with simple xml-files (Eclipse has a special editor: New->Component Definition). A service implementation is registered against an interface (or any java class) to the osgi framework and may depend on on other services which will be injected into your implementation (not unlike Spring or Guice would do). You are able to specify the cardinality of the dependancy and the dynamic behaviour (with OSGi services can come and go at any time). I love ds and recommend it wholeheartedly. The only drawback is the tooling in eclipse which is usable but certainly could be improved.

Feel free to ask further.

Mike

Previous Topic:No FrameworkStartLevel service in Indigo?
Next Topic:An error occurred while collecting items to be installed
Goto Forum:
  


Current Time: Fri Apr 19 10:26:52 GMT 2024

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

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

Back to the top