Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » OSGi sevice consumer in extensions
OSGi sevice consumer in extensions [message #645953] Tue, 21 December 2010 10:23
Florian Philipp is currently offline Florian PhilippFriend
Messages: 43
Registered: February 2010
Member
Hello!

I'd like to hear your opinion on how to incorporate OSGi services with extensions.

My problem is: In many extensions, I specifiy a class that implements some interface that can be used for this extension point. So far, so good. The extension point provider will then evaluate my extension and instantiate this class with a default constructor and use it. The problem is, most non-trivial tasks require several objects to be done. How am I supposed to get references to these other objects?

Instantiating them myself? Makes testing hard (no dependency injection) and is not always possible.

More self-defined extension points? I'd say that's overkill, though I never actually tried it so I could be wrong.

OSGi services? Sounds like a good solution but how do I gain access to the BundleContext in order to find services? Extensions usually do not receive a reference to their BundleActivator. I also do not see a way to activate them with the declarative services framework.

My current approach is to use an activator and then implement a Singleton pattern in this activator so that the Extension object can gain access to the activator through a static method.

This works reasonably well and can also be used with declarative services (by making the DS framework initialize the Singleton). However, I don't like this solution. Singletons are usually bad practice and they make testing my extensions harder and more error prone. They also force me to delcare the plugin singleton, though this is usually necessary anyway when defining Extensions.

Is there any better way to do this? Maybe some kind of Factory pattern or a way to access the BundleContext through an Eclipse API? It would be ideal if I could tell the extension framework to look for instances of the specified classes in their BundleContext but I guess that would break backward compatibility.

All I can think of is a Proxy pattern. I could wrap my actual Extension implementation in another (proxy) implementation. This proxy can then handle all static accesses to the activator and thereby decouple the rest of the business logic from any global state.

I'd like to hear your opinions on this.

Florian Philipp
Previous Topic:Eclipse RCP application and p2. Known problem, different cause?
Next Topic:P2 Update feature
Goto Forum:
  


Current Time: Fri Apr 26 22:57:26 GMT 2024

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

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

Back to the top