Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Listing / choosing from multiple implementations of a service
Listing / choosing from multiple implementations of a service [message #1699852] Sat, 27 June 2015 10:19 Go to next message
Niklas Henrich is currently offline Niklas HenrichFriend
Messages: 1
Registered: June 2015
Junior Member
Hello!

I am writing my first Eclipse RCP application, and I am not quite sure how to proceed ...

The problem is as follows: I have defined a service interface which my application is to use. But there should be different implementations of the service and the user should freely choose at runtime from one of the service implementations.

My approach now is to implement the services as "declarative plugin-ins". In the OSGI component description I state that the plugin provides the service.

My understanding is that via dependency injection of a service into my application, there are certain rules as to which implementation will be choosen.

But I want to get a list of all the possible implementations and let the user decide.

I have read something about low-level OSGI services, but I am not quite sure if this is the way to go.

Any help is greatly appreciated!

Cheers,

Niklas
Re: Listing / choosing from multiple implementations of a service [message #1699961 is a reply to message #1699852] Mon, 29 June 2015 13:22 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 672
Registered: January 2012
Senior Member

Niklas Henrich wrote on Sat, 27 June 2015 06:19
My understanding is that via dependency injection of a service into my application, there are certain rules as to which implementation will be choosen.


Providing you've setup your DI IEclipseContext hierarchy to include the special OSGi Services-based context (which is the context setup used by E4 workbench apps), the service is chosen using OSGi's BundleContext#getServiceReference() and so governed by the service.ranking property to prioritize the available OSGi Services.

Quote:

But I want to get a list of all the possible implementations and let the user decide.


You can't have both. DI is a behind-the-scenes technology, and not intended to prompt the user for decision making. In this case, I think you'd need to deal with OSGi Services directly and present to the user. You could then explicitly set their selected service in your IEclipseContext hierarchy.

Brian.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Listing / choosing from multiple implementations of a service [message #1700085 is a reply to message #1699961] Tue, 30 June 2015 05:12 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6363
Registered: July 2009
Senior Member
Brian is true in general but I wanted to add that e(fx)clipse has DI
addons who provide you access to the full list of OSGi-Services
including all the dynamics they involve.

See
https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Injection_of_OSGi-Services

You can use this part of e(fx)clipse also in SWT-RCP applications.

Tom

On 29.06.15 15:22, Brian de Alwis wrote:
> Niklas Henrich wrote on Sat, 27 June 2015 06:19
>> My understanding is that via dependency injection of a service into my
>> application, there are certain rules as to which implementation will
>> be choosen.
>
>
> Providing you've setup your DI IEclipseContext hierarchy to include the
> special OSGi Services-based context (which is the context setup used by
> E4 workbench apps), the service is chosen using OSGi's
> BundleContext#getServiceReference() and so governed by the
> service.ranking property to prioritize the available OSGi Services.
>
> Quote:
>> But I want to get a list of all the possible implementations and let
>> the user decide.
>
>
> You can't have both. DI is a behind-the-scenes technology, and not
> intended to prompt the user for decision making. In this case, I think
> you'd need to deal with OSGi Services directly and present to the user.
> You could then explicitly set their selected service in your
> IEclipseContext hierarchy.
>
> Brian.
Previous Topic:Part not displayed on exported product
Next Topic:product launch and feature dependencies
Goto Forum:
  


Current Time: Mon Nov 20 13:56:24 GMT 2017

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

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