Yes it does. You are correct. In reality, you do not need to register a BongoFactory service as no one will use that service and you really do not want anyone actually using the component other than the OSGi framework. You should just make it an immediate component.
@Component(immediate=true, service={})
class BongoFactory ...
In order to tell the resolver that someone provides the Bongo service, decorate the immediate component with service capability (use the proper fully qualified name for the Bongo class).
Only if all the constructor arguments are already services. That may not be appropriate.
I think using an immediate component to register the service using a service factory and decorating it with the service capability is the proper solution here.
Ah, thanks. I think this will also resolve my other worry that the framework would be unaware that the Bongo service âdependsâ on the BongoFactory component.
package com.acme;
import org.osgi.framework.Bundle;
public class Acme {
private final Bundle bundle;
public Acme(Bundle bundle) {
this.bundle = bundle;
}
public void doSomething() {
bundle.getBundleContext();
}
public void close() {
// any close actions
}
}
Thank you kindly for all who contributed to this thread. Iâve managed to adapt @bjhargrave 's example to my use case (though I used a PrototypeServiceFactory rather than a plain ServiceFactory). This has noteably simplified the client-side of my code.