Declarative Services is amazing, so this is trivially easy to do. In this case 
you should add the configuration property

service.target

to your configuration dictionary with the value being an LDAP filter selecting 
the service you want to inject. 

Note that “service” is the name of your reference (it defaults to the field 
name) and that if your reference has a different name (e.g. if you change the 
name of the field) then the name of the property will change too.

For example:

service.target=(foo=bar)

Inject me with a MyInterfaceB which has the service property foo equal to bar.

All the best,

Tim

> On 15 May 2019, at 14:35, Matthias Leinweber 
> <[email protected]> wrote:
> 
> Hello Karaf Experts,
> 
> i am trying to isolate services from each other. 
> 
> For Example you have a component:
> 
> @Component(
>     configurationPid = "MyInterfacA.factory",
>     configurationPolicy = ConfigurationPolicy.REQUIRE,
> public Class MyInterfaceAImpl implements MyInterfacA{
> 
> @Reference
> MyInterfaceB service;
> 
>  ...}
> 
> During runtime I create multiple services from type MyInterfaceB and multiple 
> componentes of MyInterfaceAImpl with configadmin.
> Depending on the configuration of MyInterfaceAImpl I want to filter which 
> MyInterfaceB implementation is injected.
> 
> I thought about FindHook but there I dont see a way how to get the 
> information which service from the bundle is requesting the reference.
> 
> Is there any chance to do this, or do I have to go for an alternative design. 
> Or a better way to isolate services from another?
> 
> 
> Best regards,
> Matthias

Reply via email to