SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Dependency Injection – Spring, Guice, OSGi

Dependency Injection – Spring, Guice, OSGi
Robert Munteanu, Adobe Systems Inc

http://robert.muntea.nu

@rombert
$ whoami

$DAYJOB
•

Computer Scientist at
Adobe Systems Inc

FOSS
•

Apache Sling

•

MantisBT

•

•

http://robert.muntea.nu

Mylyn Connector for
MantisBT
Mylyn Connector for
Review Board

@rombert
Why Dependency Injection?
•

Drive out accidental complexity
•

•

Leave the boilerplate to others

Decouple collaborators
•

Increase reusability

•

Ease testing

•

Increase coherence

http://robert.muntea.nu

@rombert
Accidental complexity – locating a service
ctx = new InitialContext();
ds =
(DataSource)ctx.lookup("jdbc/fastCoffeeDB");

http://robert.muntea.nu

@rombert
Accidental complexity – manually wiring components
DataSource ds = getDataSource(); // OK impl ;-)
AddressDao dao = new AddressDao(ds);
PersistenceComponent pc = new
PersistenceComponent(dao);
ServerConfig cfg = new ServerConfig(props);
ServerComponent sc = new ServerComponent(cfg);
Application app = new
Application(Arrays.asList(pc, sc));
app.start();

http://robert.muntea.nu

@rombert
Decouple collaborators – ease testing
public class ServiceMonitor {
public notifyIfDown() {
Service s =
ServiceFactory.getServiceToCheck();
try

{

s.connect()
} catch ( ServiceException e) {
ServiceFactory.getNotificationService().notifyOf
(e);
}
}
}
http://robert.muntea.nu

@rombert
Decouple collaborators – increase reusability

Service 2
Service 1
Service
AppContext 1

http://robert.muntea.nu

@rombert
Decouple collaborators – increase coherence

TextFormatter

EmailSender

SmtpService

RecipientFinder

http://robert.muntea.nu

@rombert
Dependency Injection – walkthrough

Image courtesy of FreeFoto.com

http://robert.muntea.nu

@rombert
Dependency Injection – walkthrough
Email Sender App

Technologies

Deliver formatted email
to large number of
recipients

Spring 3.2 - JavaConfig

http://robert.muntea.nu

Guice 3.0
OSGi DS 1.6.2

@rombert
Dependency Injection – bottom line
All frameworks prevent accidental complexity

•

Different binding approaches

•

•

Spring binds beans

•

Guice and OSGi bind services to consumers

Different approaches to run-time composition

•

•

Spring and Guice have a static view of the world

•

OSGi is dynamic by definition

•

Which view is right for you?

http://robert.muntea.nu

@rombert
Dependency Injection – bottom line
Different approaches to scopes

•

•

Spring and OSGi default to singleton

•

Guice defaults to instance

Different approaches to instantation

•

•

Spring and Guice default to eager

•

OSGi (SCR) defaults to lazy

http://robert.muntea.nu

@rombert
Dependency Injection – resources

https://github.com/rombert/email-sender
Dependency Injection – Dhanji R. Prasanna
Java Application Arhitecture – Kirk Knoernschild

http://robert.muntea.nu

@rombert
Dependency Injection – getting a hold of services

Q&A

http://robert.muntea.nu

@rombert

Más contenido relacionado

Destacado

Spring Dynamic Modules for OSGi by Example - Martin Lippert, Consultant
Spring Dynamic Modules for OSGi by Example - Martin Lippert, ConsultantSpring Dynamic Modules for OSGi by Example - Martin Lippert, Consultant
Spring Dynamic Modules for OSGi by Example - Martin Lippert, Consultant
mfrancis
 
Text 4 superlatives ok
Text 4 superlatives okText 4 superlatives ok
Text 4 superlatives ok
IES EUROPA
 
Blackwell Esteem AFSL
Blackwell Esteem AFSLBlackwell Esteem AFSL
Blackwell Esteem AFSL
samueltay77
 
Jill lintner's portfolio
Jill lintner's portfolioJill lintner's portfolio
Jill lintner's portfolio
ocwebservices
 

Destacado (17)

Apache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayApache Sling as a Microservices Gateway
Apache Sling as a Microservices Gateway
 
Spring Dynamic Modules for OSGi by Example - Martin Lippert, Consultant
Spring Dynamic Modules for OSGi by Example - Martin Lippert, ConsultantSpring Dynamic Modules for OSGi by Example - Martin Lippert, Consultant
Spring Dynamic Modules for OSGi by Example - Martin Lippert, Consultant
 
Ciclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scpCiclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scp
 
rajesh - Updated
rajesh - Updatedrajesh - Updated
rajesh - Updated
 
Horizons Beyond Dreams Business Plan
Horizons Beyond Dreams Business PlanHorizons Beyond Dreams Business Plan
Horizons Beyond Dreams Business Plan
 
The Praying Indians of Megunko
The Praying Indians of MegunkoThe Praying Indians of Megunko
The Praying Indians of Megunko
 
ROR -Igal Assaf Paris sous la neige
ROR -Igal Assaf  Paris sous la neigeROR -Igal Assaf  Paris sous la neige
ROR -Igal Assaf Paris sous la neige
 
Text 4 superlatives ok
Text 4 superlatives okText 4 superlatives ok
Text 4 superlatives ok
 
Report..costing..
Report..costing..Report..costing..
Report..costing..
 
Exposing Opportunities in China A50 using CFD
Exposing Opportunities in China A50 using CFDExposing Opportunities in China A50 using CFD
Exposing Opportunities in China A50 using CFD
 
SGGSWU Prospectus 2016-17
SGGSWU Prospectus 2016-17SGGSWU Prospectus 2016-17
SGGSWU Prospectus 2016-17
 
Where can tell me who I am?
Where can tell me who I am?Where can tell me who I am?
Where can tell me who I am?
 
Blackwell Esteem AFSL
Blackwell Esteem AFSLBlackwell Esteem AFSL
Blackwell Esteem AFSL
 
Li & fung ltd
Li & fung ltdLi & fung ltd
Li & fung ltd
 
Jill lintner's portfolio
Jill lintner's portfolioJill lintner's portfolio
Jill lintner's portfolio
 
sdfghjk
sdfghjksdfghjk
sdfghjk
 
Good prescribing
Good prescribingGood prescribing
Good prescribing
 

Más de Robert Munteanu

Más de Robert Munteanu (20)

Secure by Default Web Applications
Secure by Default Web ApplicationsSecure by Default Web Applications
Secure by Default Web Applications
 
Sling Applications - A DevOps perspective
Sling Applications - A DevOps perspectiveSling Applications - A DevOps perspective
Sling Applications - A DevOps perspective
 
Will it blend? Java agents and OSGi
Will it blend? Java agents and OSGiWill it blend? Java agents and OSGi
Will it blend? Java agents and OSGi
 
Escape the defaults - Configure Sling like AEM as a Cloud Service
Escape the defaults - Configure Sling like AEM as a Cloud ServiceEscape the defaults - Configure Sling like AEM as a Cloud Service
Escape the defaults - Configure Sling like AEM as a Cloud Service
 
Crash course in Kubernetes monitoring
Crash course in Kubernetes monitoringCrash course in Kubernetes monitoring
Crash course in Kubernetes monitoring
 
Java agents for fun and (not so much) profit
Java agents for fun and (not so much) profitJava agents for fun and (not so much) profit
Java agents for fun and (not so much) profit
 
Will it blend? Java agents and OSGi
Will it blend? Java agents and OSGiWill it blend? Java agents and OSGi
Will it blend? Java agents and OSGi
 
Cloud-native legacy applications
Cloud-native legacy applicationsCloud-native legacy applications
Cloud-native legacy applications
 
Cloud-Native Sling
Cloud-Native SlingCloud-Native Sling
Cloud-Native Sling
 
From Monolith to Modules - breaking apart a one size fits all product into mo...
From Monolith to Modules - breaking apart a one size fits all product into mo...From Monolith to Modules - breaking apart a one size fits all product into mo...
From Monolith to Modules - breaking apart a one size fits all product into mo...
 
What's new in the Sling developer tooling?
What's new in the Sling developer tooling?What's new in the Sling developer tooling?
What's new in the Sling developer tooling?
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Zero downtime deployments for Sling application using Docker
Zero downtime deployments for Sling application using DockerZero downtime deployments for Sling application using Docker
Zero downtime deployments for Sling application using Docker
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Secure by Default Web Applications with Apache Sling
Secure by Default Web Applications with Apache SlingSecure by Default Web Applications with Apache Sling
Secure by Default Web Applications with Apache Sling
 
Effective Web Application Development with Apache Sling
Effective Web Application Development with Apache SlingEffective Web Application Development with Apache Sling
Effective Web Application Development with Apache Sling
 
Building domain-specific testing tools : lessons learned from the Apache Slin...
Building domain-specific testing tools : lessons learned from the Apache Slin...Building domain-specific testing tools : lessons learned from the Apache Slin...
Building domain-specific testing tools : lessons learned from the Apache Slin...
 
So how do I test my Sling application?
 So how do I test my Sling application? So how do I test my Sling application?
So how do I test my Sling application?
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Dependency injection: Spring, Guice, OSGi

  • 1. Dependency Injection – Spring, Guice, OSGi Dependency Injection – Spring, Guice, OSGi Robert Munteanu, Adobe Systems Inc http://robert.muntea.nu @rombert
  • 2. $ whoami $DAYJOB • Computer Scientist at Adobe Systems Inc FOSS • Apache Sling • MantisBT • • http://robert.muntea.nu Mylyn Connector for MantisBT Mylyn Connector for Review Board @rombert
  • 3. Why Dependency Injection? • Drive out accidental complexity • • Leave the boilerplate to others Decouple collaborators • Increase reusability • Ease testing • Increase coherence http://robert.muntea.nu @rombert
  • 4. Accidental complexity – locating a service ctx = new InitialContext(); ds = (DataSource)ctx.lookup("jdbc/fastCoffeeDB"); http://robert.muntea.nu @rombert
  • 5. Accidental complexity – manually wiring components DataSource ds = getDataSource(); // OK impl ;-) AddressDao dao = new AddressDao(ds); PersistenceComponent pc = new PersistenceComponent(dao); ServerConfig cfg = new ServerConfig(props); ServerComponent sc = new ServerComponent(cfg); Application app = new Application(Arrays.asList(pc, sc)); app.start(); http://robert.muntea.nu @rombert
  • 6. Decouple collaborators – ease testing public class ServiceMonitor { public notifyIfDown() { Service s = ServiceFactory.getServiceToCheck(); try { s.connect() } catch ( ServiceException e) { ServiceFactory.getNotificationService().notifyOf (e); } } } http://robert.muntea.nu @rombert
  • 7. Decouple collaborators – increase reusability Service 2 Service 1 Service AppContext 1 http://robert.muntea.nu @rombert
  • 8. Decouple collaborators – increase coherence TextFormatter EmailSender SmtpService RecipientFinder http://robert.muntea.nu @rombert
  • 9. Dependency Injection – walkthrough Image courtesy of FreeFoto.com http://robert.muntea.nu @rombert
  • 10. Dependency Injection – walkthrough Email Sender App Technologies Deliver formatted email to large number of recipients Spring 3.2 - JavaConfig http://robert.muntea.nu Guice 3.0 OSGi DS 1.6.2 @rombert
  • 11. Dependency Injection – bottom line All frameworks prevent accidental complexity • Different binding approaches • • Spring binds beans • Guice and OSGi bind services to consumers Different approaches to run-time composition • • Spring and Guice have a static view of the world • OSGi is dynamic by definition • Which view is right for you? http://robert.muntea.nu @rombert
  • 12. Dependency Injection – bottom line Different approaches to scopes • • Spring and OSGi default to singleton • Guice defaults to instance Different approaches to instantation • • Spring and Guice default to eager • OSGi (SCR) defaults to lazy http://robert.muntea.nu @rombert
  • 13. Dependency Injection – resources https://github.com/rombert/email-sender Dependency Injection – Dhanji R. Prasanna Java Application Arhitecture – Kirk Knoernschild http://robert.muntea.nu @rombert
  • 14. Dependency Injection – getting a hold of services Q&A http://robert.muntea.nu @rombert