Thank you Tim,

Ok thats really amazing! That was exactly what i was looking for.

I can change the name target name with @Referance(name="foo") so a bit more 
transparency.


Each day I am discovering something like this i like OSGI and Karaf a bit more.


br,

Matthias

________________________________
Von: Tim Ward <tim.w...@paremus.com>
Gesendet: Mittwoch, 15. Mai 2019 15:45:20
An: user@karaf.apache.org
Betreff: Re: Service Sisibility

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 
<matthias.leinwe...@ida-analytics.de<mailto:matthias.leinwe...@ida-analytics.de>>
 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