views:

555

answers:

1

Apache Felix's SCR allows to declare (via annotations or XML) components that will then be instantiated, hooked up to their dependencies, and registered as OSGi services.

It is also possible to skip the service registration part, and just have SCR create the component (by specifying @scr.component, but omitting @scr.service). I was thinking this might be useful just for the dependency-injection (within the bundle), but how does one consume the components? Services can be injected using scr.reference, but this does not work for non-services (or does it)?

Accessing the SCR API directly works, but directly talking to container services kind of defeats the purpose of DI.

+2  A: 

I think you are only able to inject OSGI services. If you want to use dependency injection maybe you should check google Guice. Unfortunately I don't know if it works out of the box inside a OSGI container.

Regarding SCR components, if a component provides functionality that you want to use in another component, I think it should be exposed using a service.

jassuncao