In the JavaEE/CDI world, I know how to have the list of instances of classes implementing a given interface : by using Instance<MyInterface>
combined with reflections library.
But in the OSGI/iPOJO world, how to do so ?
I know I get one instance by using @Requires MyInterface anInstance
. But how can I have a programmatic access to all those classes ?
Just use the BundleContext
:
@Context BundleContext context;
public List<ServiceReference> getInstancesImplementingX() {
return context.getServiceReferences(X.class);
}