Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relationship between OSGi and Dependency Injection

What are they of each other?

  • Specification and implementation?
  • Competitors?
  • Unrelated?
like image 259
flybywire Avatar asked Aug 31 '09 12:08

flybywire


1 Answers

The OSGi specification is composed of two separated parts: core and compendium.

The core part is the specification of a module system for Java. As such, the core specification has no relationship with the concept of DI.

The compendium part, on the other side, specifies a series of services that an OSGi container can provide. Among this services you'll find the "Declarative Services Specification" (OSGi Compendium Services, Chapter 112) that is the first attempt to bring the familiar concept of DI into OSGi. The idea is simple: since OSGi allows the developer to implement, define and register services, the Declarative Services Specification gives the developer the possibility to define a service dependent on a series of other underlying services. That's a particularly interesting (and hard) problem in OSGi, because services are by definition unreliable, and they can appear and disappear.

Beside the Declarative Services Specification, there are at least two other popular solution trying to provide a more powerful DI framework in OSGi:

  • Peaberry, an extension of the Guice framework for OSGi
  • Spring Dynamic Modules for OSGi (aka Spring DM), the OSGi extension of the Spring Framework

It worth noting that the upcoming R4.2 version of the OSGi specification will contain a new compendium specification named Blueprint Services, that will provide a complete DI solution for OSGi based on the Spring DM framework (the Spring team has heavily contributed to this new specification)

like image 75
Filippo Diotalevi Avatar answered Oct 03 '22 04:10

Filippo Diotalevi