ops4j / org.ops4j.pax.cdi

Contexts and Dependency Injection for OSGi
Apache License 2.0
34 stars 26 forks source link

OSGi services chained injection [PAXCDI-154] #205

Open ops4j-issues opened 9 years ago

ops4j-issues commented 9 years ago

Krystian Panek created PAXCDI-154

I noticed strange bug. Some hierarchy description:
MyServiceAggregator could contain MyServiceA, MyServiceB. (@Inject @Any)
MyServiceA does not dependent on any other services. MyServiceB could contain OtherServiceA, OtherServiceB (@Inject @Any).

I want to grab all my services using:


@OsgiServiceProvider
public class MyServicesAgreggator {
    @Inject
    @Any
    @OsgiService(dynamic = true)
    private Instance<MyService> services;

}

And I have two implementations of MyService:

@OsgiServiceProvider
public class MyServiceA {
    // no service dependencies
}

And:

@OsgiServiceProvider
public class MyServiceB {
    // nested service injections that should be satisfied earlier
    @Inject
    @Any
    @OsgiService(dynamic = true)
    private Instance<OtherService> otherServices;

}

MyServiceB is injected into MyServiceAggregator only if MyServiceA exists / is available. If not, I am getting an error:

Caused by: javax.enterprise.inject.UnsatisfiedResolutionException
    at org.ops4j.pax.cdi.extension.impl.client.OsgiServiceInstance.get(OsgiServiceInstance.java:61)

For me it is a heavy blocker. I am forced to have a workaround which is an empty implementation without any dependencies to get all working.
In documentation I found that optional injections are planned in further release. Do you have any estimate / roadmap?


Affects: 0.11.0 Fixed in: 1.1.4 Votes: 1, Watches: 4

ops4j-issues commented 9 years ago

Harald Wellmann commented

I made some changes in a related area a while ago, but I can't tell off of my head if that covers your problem.

Could you please try a current 1.0.0-SNAPSHOT?

If you still see the same exception, then contributing a test case is always a good way to see the problem fixed in a coming release :wink:

ops4j-issues commented 9 years ago

Krystian Panek commented

Of source, I am busy currently but I will try discover it on Monday.

Regards

ops4j-issues commented 9 years ago

Harald Wellmann commented

Postponed for lack of input.

ops4j-issues commented 9 years ago

Krystian Panek commented

I noticed your activity for preparing 1.0 release so I will try to help with this issue soon... I really care about this issue. Sorry for no reaction before. I haven't enough time for it.