OSGi CDI Integration Specification
Raymond Augé - Sr. So ware Architect
@rotty3000
Why CDI In OSGi?
Important Java specification
Reduce developer friction
Benefit from extensive feature set
@rotty3000
CDI - Features
as part of its feature set, is...
extensible (CDI has a full fledged SPI)
annotation processing engine
intra-bundle dependency injection
Custom annotations!
@rotty3000
CDI - Internal wiring: @Inject
@rotty3000
import javax.inject.Inject;
public class PresenterImpl implements Presenter {
private final Laptop laptop;
@Inject
public PresenterImpl(Laptop laptop) {
this.laptop = laptop;
}
}
1
2
3
4
5
6
7
8
9
10
CDI - Internal wiring: @Produces
@rotty3000
import javax.enterprise.inject.Produces;
@Produces Presentation presentation(
LocalDate date, Presenter presenter, @Topic String
topic,
Details details) {
return new Presentation.Builder(date)
.withPresenter(presenter)
.withTopic(topic)
.withDetails(details)
.build();
}
1
2
3
4
5
6
7
8
9
10
11
12
OSGi-CDI - Services: singleton
@rotty3000
import org.osgi.service.cdi.annotations.Service;
@Service
public class PresenterImpl implements Presenter {
...
}
1
2
3
4
5
6
OSGi-CDI - Services: prototype
@rotty3000
import org.osgi.service.cdi.annotations.Service;
import org.osgi.service.cdi.annotations.ServiceInstance;
@Service @ServiceInstance(PROTOTYPE)
public class Beer implements Drink {
...
}
1
2
3
4
5
6
7
OSGi-CDI - References to OSGi Services
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
Presenter presenter;
1
2
3
4
5
OSGi-CDI - References Cardinality: mandatory
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
Presenter presenter;
1
2
3
4
5
OSGi-CDI - References Cardinality: optional
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
Optional<Drink> drink;
1
2
3
4
5
OSGi-CDI - References Cardinality: multiple
... implies 0..n (multiple optional)
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
List<Drink> drink;
1
2
3
4
5
OSGi-CDI - References Cardinality: at least one
(or n)
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.MinimumCardinality;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference @MinimumCardinality(1)
List<Drink> drink;
1
2
3
4
5
6
OSGi-CDI - Reference Policy: reluctant
... reference is Greedy by default
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
import org.osgi.service.cdi.annotations.Reluctant;
@Inject @Reference @Reluctant
Presenter presenter;
1
2
3
4
5
6
OSGi-CDI - References Dynamic: mandatory
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
Provider<Presenter> presenter;
1
2
3
4
5
OSGi-CDI - References Dynamic: multiple
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
Provider<List<Presenter>> presenters;
1
2
3
4
5
OSGi-CDI - References Dynamic: optional
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference
Provider<Optional<Presenter>> presenter;
1
2
3
4
5
OSGi-CDI - Reference: target
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference(target = "(service.vendor=Chicago JUG)")
List<Presenter> presenters;
1
2
3
4
5
OSGi-CDI - Reference: target
@BeanPropertyType
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
import org.osgi.service.cdi.propertytypes.ServiceVendor;
@Inject @Reference @ServiceVendor("Chicago JUG")
List<Presenter> presenters;
1
2
3
4
5
6
OSGi-CDI - Reference: prototype required
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.MinimumCardinality;
import org.osgi.service.cdi.annotations.PrototypeRequired;
import org.osgi.service.cdi.annotations.Reference;
@Inject @Reference @MinimumCardinality(1)
@PrototypeRequired
List<Entry<Map<String, Object>, Drink>> drinks;
1
2
3
4
5
6
7
OSGi-CDI - Reference: any type
... in support of whiteboards
@rotty3000
import javax.inject.Inject;
import org.osgi.service.cdi.annotations.Reference;
import org.osgi.service.cdi.propertytypes.ServiceVendor;
@Inject @Reference(service = Reference.Any.class)
@ServiceVendor("Chicago JUG")
List<Object> all;
1
2
3
4
5
6
7
OSGi-CDI - Reference: service events
@rotty3000
import javax.inject.Inject;
@Inject @ServiceVendor("Chicago JUG")
void monitorDrinks(BindServiceReference<Drink> drinks) {
drinks
.adding(this::doAdd)
.modified(this::doModified)
.removed(this::doRemoved)
.bind();
}
1
2
3
4
5
6
7
8
9
10
OSGi-CDI - OSGi Logger
@rotty3000
import javax.inject.Inject;
import org.osgi.service.log.Logger;
@Inject
Logger video;
1
2
3
4
5
OSGi-CDI - Configuration
@rotty3000
import javax.inject.Inject;
import
org.osgi.service.cdi.annotations.ComponentProperties;
@Inject @ComponentProperties
Map<String, Object> eventDetails;
1
2
3
4
5
OSGi-CDI - Configuration Types
@rotty3000
import org.osgi.service.cdi.annotations.BeanPropertyType;
@Retention(RUNTIME)
@BeanPropertyType
public @interface Details {
String address();
String instructions();
}
1
2
3
4
5
6
7
8
OSGi-CDI - Configuration: typed
@rotty3000
import javax.inject.Inject;
import
org.osgi.service.cdi.annotations.ComponentProperties;
@Inject @ComponentProperties
Details eventDetails;
1
2
3
4
5
OSGi-CDI - Single Component
@rotty3000
import org.osgi.service.cdi.annotations.PID;
import org.osgi.service.cdi.annotations.SingleComponent;
@SingleComponent
@PID(value = "details", policy = REQUIRED)
@Service
public PresenterImpl implements Presenter {
@Inject Laptop laptop;
@Inject @ComponentProperties Details eventDetails;
}
1
2
3
4
5
6
7
8
9
10
OSGi-CDI - Factory Component
@rotty3000
import org.osgi.service.cdi.annotations.PID;
import org.osgi.service.cdi.annotations.FactoryComponent;
@FactoryComponent("registration")
@PID(value = "details", policy = REQUIRED)
public class AttendeeImpl implements Attendee {
@Inject @ComponentProperties Registration registration;
@Inject @ComponentProperties Details eventDetails;
}
1
2
3
4
5
6
7
8
9
The OSGi-CDI Spec
https://osgi.org/specification/osgi.enterprise/7.0.0/service.cdi.html
@rotty3000
The OSGi-CDI Reference Implementation
https://github.com/apache/aries-cdi
@rotty3000
 

More Related Content

PDF
Show me the money!
PPTX
What's new in c# 8.0
PPTX
APIdays London 2020: Toward certifying Financial-grade API security profile w...
PDF
Automake
PDF
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
PPT
Automatic Code Generation
PDF
Build pipelines with TeamCity and Kotlin DSL
PPTX
apidays LIVE Paris 2021 - Inside API delivery Pipeline, the checklist! - Fran...
Show me the money!
What's new in c# 8.0
APIdays London 2020: Toward certifying Financial-grade API security profile w...
Automake
Vitaliy Makogon: Migration to ivy. Angular component libraries with IVY support.
Automatic Code Generation
Build pipelines with TeamCity and Kotlin DSL
apidays LIVE Paris 2021 - Inside API delivery Pipeline, the checklist! - Fran...

What's hot (20)

PDF
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
PDF
React: JSX and Top Level API
PDF
Writing testable Android apps
PDF
Lets dance- Dutch Architecture Conference (LAC) 2018
PDF
React custom renderers
PDF
[제3회 스포카콘] Elasticsearch 동기화 개선을 위한 고군분투기
PPTX
Blood, sweat, and creating an API handbook
PPTX
Pure APIs: Development workflows for successful API integrations
PDF
[Fevr] Can't live if livin' is without rendering
PDF
Use Geth to Deploy Contract
PPTX
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
PDF
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
PDF
Use Geth to Access a Deployed Contract
PDF
[제3회 스포카콘] [안드로이드] 클린 아키텍처 적용하기
PPTX
Advanced Automation in Your API Lifecycle
PPTX
Design-first API Development using Swagger and Node
PPTX
Test your microservices with REST-Assured
PPTX
A second look at Unit Testing with Roy Osherove at Microsoft Swit
PDF
Karate - powerful and simple framework for REST API automation testing
PDF
Serverless GraphQL for Product Developers
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
React: JSX and Top Level API
Writing testable Android apps
Lets dance- Dutch Architecture Conference (LAC) 2018
React custom renderers
[제3회 스포카콘] Elasticsearch 동기화 개선을 위한 고군분투기
Blood, sweat, and creating an API handbook
Pure APIs: Development workflows for successful API integrations
[Fevr] Can't live if livin' is without rendering
Use Geth to Deploy Contract
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
TDD for APIs in a Microservice World (Short Version) by Michael Kuehne-Schlin...
Use Geth to Access a Deployed Contract
[제3회 스포카콘] [안드로이드] 클린 아키텍처 적용하기
Advanced Automation in Your API Lifecycle
Design-first API Development using Swagger and Node
Test your microservices with REST-Assured
A second look at Unit Testing with Roy Osherove at Microsoft Swit
Karate - powerful and simple framework for REST API automation testing
Serverless GraphQL for Product Developers
Ad

Similar to OSGi CDI Integration Specification -- Raymond Augé, Liferay (17)

PDF
CDI Integration in OSGi - Emily Jiang
PDF
Osgi cdi
PDF
CDI and OSGi so happy together! - R Auge
PDF
CDI In Real Life
PDF
Weld-OSGi, injecting easiness in OSGi
PDF
The path to cdi 2.0
PDF
JAX 09 - OSGi Service Components Models
PPTX
J2ee standards > CDI
PDF
Dynamic and modular Web Applications with Equinox and Vaadin
PDF
CDI 2.0 is coming
PDF
OSGi CDI Integration Specification - Ray Augé (Liferay)
PDF
CDI Best Practices with Real-Life Examples - TUT3287
PDF
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
PDF
What's new in the OSGi 4.2 Enterprise Release
PDF
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
PDF
Karaf ee-apachecon eu-2012
CDI Integration in OSGi - Emily Jiang
Osgi cdi
CDI and OSGi so happy together! - R Auge
CDI In Real Life
Weld-OSGi, injecting easiness in OSGi
The path to cdi 2.0
JAX 09 - OSGi Service Components Models
J2ee standards > CDI
Dynamic and modular Web Applications with Equinox and Vaadin
CDI 2.0 is coming
OSGi CDI Integration Specification - Ray Augé (Liferay)
CDI Best Practices with Real-Life Examples - TUT3287
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
What's new in the OSGi 4.2 Enterprise Release
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Karaf ee-apachecon eu-2012
Ad

Recently uploaded (20)

PDF
Five Habits of High-Impact Board Members
PDF
Unlock new opportunities with location data.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Architecture types and enterprise applications.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
DOCX
search engine optimization ppt fir known well about this
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPT
Geologic Time for studying geology for geologist
PPTX
The various Industrial Revolutions .pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Five Habits of High-Impact Board Members
Unlock new opportunities with location data.pdf
Modernising the Digital Integration Hub
Architecture types and enterprise applications.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
search engine optimization ppt fir known well about this
Module 1.ppt Iot fundamentals and Architecture
Assigned Numbers - 2025 - Bluetooth® Document
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
sustainability-14-14877-v2.pddhzftheheeeee
Geologic Time for studying geology for geologist
The various Industrial Revolutions .pptx
Getting started with AI Agents and Multi-Agent Systems
Tartificialntelligence_presentation.pptx
Web Crawler for Trend Tracking Gen Z Insights.pptx
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf

OSGi CDI Integration Specification -- Raymond Augé, Liferay

  • 1.       OSGi CDI Integration Specification Raymond Augé - Sr. So ware Architect @rotty3000
  • 2. Why CDI In OSGi? Important Java specification Reduce developer friction Benefit from extensive feature set @rotty3000
  • 3. CDI - Features as part of its feature set, is... extensible (CDI has a full fledged SPI) annotation processing engine intra-bundle dependency injection Custom annotations! @rotty3000
  • 4. CDI - Internal wiring: @Inject @rotty3000 import javax.inject.Inject; public class PresenterImpl implements Presenter { private final Laptop laptop; @Inject public PresenterImpl(Laptop laptop) { this.laptop = laptop; } } 1 2 3 4 5 6 7 8 9 10
  • 5. CDI - Internal wiring: @Produces @rotty3000 import javax.enterprise.inject.Produces; @Produces Presentation presentation( LocalDate date, Presenter presenter, @Topic String topic, Details details) { return new Presentation.Builder(date) .withPresenter(presenter) .withTopic(topic) .withDetails(details) .build(); } 1 2 3 4 5 6 7 8 9 10 11 12
  • 6. OSGi-CDI - Services: singleton @rotty3000 import org.osgi.service.cdi.annotations.Service; @Service public class PresenterImpl implements Presenter { ... } 1 2 3 4 5 6
  • 7. OSGi-CDI - Services: prototype @rotty3000 import org.osgi.service.cdi.annotations.Service; import org.osgi.service.cdi.annotations.ServiceInstance; @Service @ServiceInstance(PROTOTYPE) public class Beer implements Drink { ... } 1 2 3 4 5 6 7
  • 8. OSGi-CDI - References to OSGi Services @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Presenter presenter; 1 2 3 4 5
  • 9. OSGi-CDI - References Cardinality: mandatory @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Presenter presenter; 1 2 3 4 5
  • 10. OSGi-CDI - References Cardinality: optional @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Optional<Drink> drink; 1 2 3 4 5
  • 11. OSGi-CDI - References Cardinality: multiple ... implies 0..n (multiple optional) @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference List<Drink> drink; 1 2 3 4 5
  • 12. OSGi-CDI - References Cardinality: at least one (or n) @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.MinimumCardinality; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference @MinimumCardinality(1) List<Drink> drink; 1 2 3 4 5 6
  • 13. OSGi-CDI - Reference Policy: reluctant ... reference is Greedy by default @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; import org.osgi.service.cdi.annotations.Reluctant; @Inject @Reference @Reluctant Presenter presenter; 1 2 3 4 5 6
  • 14. OSGi-CDI - References Dynamic: mandatory @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Provider<Presenter> presenter; 1 2 3 4 5
  • 15. OSGi-CDI - References Dynamic: multiple @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Provider<List<Presenter>> presenters; 1 2 3 4 5
  • 16. OSGi-CDI - References Dynamic: optional @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference Provider<Optional<Presenter>> presenter; 1 2 3 4 5
  • 17. OSGi-CDI - Reference: target @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference(target = "(service.vendor=Chicago JUG)") List<Presenter> presenters; 1 2 3 4 5
  • 18. OSGi-CDI - Reference: target @BeanPropertyType @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; import org.osgi.service.cdi.propertytypes.ServiceVendor; @Inject @Reference @ServiceVendor("Chicago JUG") List<Presenter> presenters; 1 2 3 4 5 6
  • 19. OSGi-CDI - Reference: prototype required @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.MinimumCardinality; import org.osgi.service.cdi.annotations.PrototypeRequired; import org.osgi.service.cdi.annotations.Reference; @Inject @Reference @MinimumCardinality(1) @PrototypeRequired List<Entry<Map<String, Object>, Drink>> drinks; 1 2 3 4 5 6 7
  • 20. OSGi-CDI - Reference: any type ... in support of whiteboards @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.Reference; import org.osgi.service.cdi.propertytypes.ServiceVendor; @Inject @Reference(service = Reference.Any.class) @ServiceVendor("Chicago JUG") List<Object> all; 1 2 3 4 5 6 7
  • 21. OSGi-CDI - Reference: service events @rotty3000 import javax.inject.Inject; @Inject @ServiceVendor("Chicago JUG") void monitorDrinks(BindServiceReference<Drink> drinks) { drinks .adding(this::doAdd) .modified(this::doModified) .removed(this::doRemoved) .bind(); } 1 2 3 4 5 6 7 8 9 10
  • 22. OSGi-CDI - OSGi Logger @rotty3000 import javax.inject.Inject; import org.osgi.service.log.Logger; @Inject Logger video; 1 2 3 4 5
  • 23. OSGi-CDI - Configuration @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.ComponentProperties; @Inject @ComponentProperties Map<String, Object> eventDetails; 1 2 3 4 5
  • 24. OSGi-CDI - Configuration Types @rotty3000 import org.osgi.service.cdi.annotations.BeanPropertyType; @Retention(RUNTIME) @BeanPropertyType public @interface Details { String address(); String instructions(); } 1 2 3 4 5 6 7 8
  • 25. OSGi-CDI - Configuration: typed @rotty3000 import javax.inject.Inject; import org.osgi.service.cdi.annotations.ComponentProperties; @Inject @ComponentProperties Details eventDetails; 1 2 3 4 5
  • 26. OSGi-CDI - Single Component @rotty3000 import org.osgi.service.cdi.annotations.PID; import org.osgi.service.cdi.annotations.SingleComponent; @SingleComponent @PID(value = "details", policy = REQUIRED) @Service public PresenterImpl implements Presenter { @Inject Laptop laptop; @Inject @ComponentProperties Details eventDetails; } 1 2 3 4 5 6 7 8 9 10
  • 27. OSGi-CDI - Factory Component @rotty3000 import org.osgi.service.cdi.annotations.PID; import org.osgi.service.cdi.annotations.FactoryComponent; @FactoryComponent("registration") @PID(value = "details", policy = REQUIRED) public class AttendeeImpl implements Attendee { @Inject @ComponentProperties Registration registration; @Inject @ComponentProperties Details eventDetails; } 1 2 3 4 5 6 7 8 9
  • 29. The OSGi-CDI Reference Implementation https://github.com/apache/aries-cdi @rotty3000