OsgiServiceProvider vs Service, OsgiService vs Reference

761 views
Skip to first unread message

Ranx0r0x

unread,
Sep 3, 2016, 2:13:02 PM9/3/16
to OPS4J
One thing that isn't clear to me from the documentation is how the annotations vary.

I know that if I use the Service/Reference annotations they work in the CDI test runner just fine.  The OsgiServiceProvider and OsgiService annotations do not.  I haven't put them in karaf/felix as deployments yet.  But the Service/Reference should work I'd think since the are felix annotations.

Is it that the Service/Reference annotations are not portable across container types - that is Equinox, Knopplerfish, in addition to Felix while the Osgi...Service annotations should be?  Or is it that the Osgi types are differentiated by using proxies while the Service/Reference annotations are strictly DS?

Other than the testing concern why would I choose one over the other?

Brad

Achim Nierbeck

unread,
Sep 3, 2016, 4:03:02 PM9/3/16
to op...@googlegroups.com
Hi, 

looks like you mix two different things, one is CDI (as with JEE), the other is Declarative Services. 
The first will give you std. Contexte and Dependency Injection, for example Bean wiring within the same Bundle (classic dependency injection) etc. when combined with Pax-CDI you're able to Inject OSGi Services into your Bean Context created by either other Pax-CDI enabled CDI bundles or standard OSGi services. 

Now talking of Service/Reference annotated services and references. Those are std. Declarative Services and will work with any OSGi Implementation of that Specification. Now those are "portable" accross different frameworks (Equinox, Knopflerfish, etc..) if there is a bundle available that implements the OSGi specification for Declarative Services. 

The annotations: 
- Reference 
is a Declarative Services annotation and will only work with OSGi runtimes as it wires any other OSGi service into your consuming class

- Service 
is a Declarative Services annotation and also will only work within an OSGi environment. It declares this class as a OSGi service which can be referenced in any OSGi way – one, for example could be via Declarative Services Reference annotation. 

- OsgiServiceProvider
is a Pax-CDI annotation to declare any CDI bean to also be registered as OSGi Service, this will only work if Pax-CDI is available. CDI isn't standardized within the OSGi specifications yet. 

- OsgiService
is also a Pax-CDI annotation. With this you're able to inject any kind of OSGi Service in your CDI managed bean context, and therefore into that given CDI Bean. Actually it might be that you reference a Service which is made available via the @Service annotation in a DS bundle. 


One major difference between CDI and DS is, CDI will give you bean wiring within your bundle and services while DS only gives you wiring between services, so DS is more coarse grained. 

Hope this made it clearer for you. 

regards, Achim 


--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Apache Member
Apache Karaf <http://karaf.apache.org/> Committer & PMC
OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer & Project Lead
blog <http://notizblog.nierbeck.de/>
Co-Author of Apache Karaf Cookbook <http://bit.ly/1ps9rkS>

Software Architect / Project Manager / Scrum Master 

Reply all
Reply to author
Forward
0 new messages