SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

Apache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayApache Sling as a Microservices Gateway
Apache Sling as a Microservices GatewayRobert Munteanu
 
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, Consultantmfrancis
 
Ciclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scpCiclo basico diurno vigencia 2009 scp
Ciclo basico diurno vigencia 2009 scpRuth Santana
 
Horizons Beyond Dreams Business Plan
Horizons Beyond Dreams Business PlanHorizons Beyond Dreams Business Plan
Horizons Beyond Dreams Business Planphillipcfrankis
 
The Praying Indians of Megunko
The Praying Indians of MegunkoThe Praying Indians of Megunko
The Praying Indians of Megunkopebrodeur
 
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 neigeIgal Assaf
 
Text 4 superlatives ok
Text 4 superlatives okText 4 superlatives ok
Text 4 superlatives okIES EUROPA
 
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 CFDPhillip CFD
 
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?seltzoid
 
Blackwell Esteem AFSL
Blackwell Esteem AFSLBlackwell Esteem AFSL
Blackwell Esteem AFSLsamueltay77
 
Jill lintner's portfolio
Jill lintner's portfolioJill lintner's portfolio
Jill lintner's portfolioocwebservices
 

Andere mochten auch (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
 

Mehr von Robert Munteanu

Secure by Default Web Applications
Secure by Default Web ApplicationsSecure by Default Web Applications
Secure by Default Web ApplicationsRobert Munteanu
 
Sling Applications - A DevOps perspective
Sling Applications - A DevOps perspectiveSling Applications - A DevOps perspective
Sling Applications - A DevOps perspectiveRobert Munteanu
 
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 OSGiRobert Munteanu
 
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 ServiceRobert Munteanu
 
Crash course in Kubernetes monitoring
Crash course in Kubernetes monitoringCrash course in Kubernetes monitoring
Crash course in Kubernetes monitoringRobert Munteanu
 
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) profitRobert Munteanu
 
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 OSGiRobert Munteanu
 
Cloud-native legacy applications
Cloud-native legacy applicationsCloud-native legacy applications
Cloud-native legacy applicationsRobert Munteanu
 
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...Robert Munteanu
 
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?Robert Munteanu
 
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 baseRobert Munteanu
 
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 baseRobert Munteanu
 
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 baseRobert Munteanu
 
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 DockerRobert Munteanu
 
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 baseRobert Munteanu
 
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 SlingRobert Munteanu
 
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 SlingRobert Munteanu
 
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...Robert Munteanu
 
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?Robert Munteanu
 

Mehr von 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?
 

Kürzlich hochgeladen

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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 challengesrafiqahmad00786416
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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.pdfsudhanshuwaghmare1
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
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 businesspanagenda
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Kürzlich hochgeladen (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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