SlideShare a Scribd company logo
1 of 30
Dependency Injection (DI) Or stop cooking spaghetti (code)
1 			    “Dependency Injection                           is a key element                     of agile architecture” Ward Cunningham
Dependency Injection (DI) is not a pattern, but rather a set of tools 2
DIisone of the ways to applyInversion of Control (IoC) principle 3
Literally – let go off control and let someone feed you 4
Example Task Obviously its time to go to code . Check out NoDI project. 5
Specifications are singing rigoletto 6
Specs tend to change 7
Highly coupled code is a step to spaghetti code 8 Can’t intercept and change code; Can’t unit-test in isolation; Conceptual problems in modules design; Logic is spread across many parts.
Divide et impera 9 DI’s base is Interface Oriented Programming. Write your code against abstractions rather then concrete implementations.
Single Responsibility Principle (SRP) 10 By applying DI to class we let it “concentrate” on task it was designed for.
Modularity ,[object Object]
Reuse;
Build in parallel;
Easier to maintain;
Easier to unit-test.Go on and check this stuff applied in PoorMansDI project. 11
DI patterns. 12
Composition Root 13
Constructor injection 14
Property (setter) injection 15
Method injection 16
Ambient context 17
Which one to choose? 18
3D of DI 19
1. Composition 20
2. Lifetime Management 21 ,[object Object]
Singleton;
Per thread;
Per web request;
Per web session;

More Related Content

Viewers also liked

Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...
Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...
Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...Trøndelag Reiseliv
 
Abstinence as programming practice
Abstinence as programming practiceAbstinence as programming practice
Abstinence as programming practiceBoris Tveritnev
 
Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...
Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...
Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...Trøndelag Reiseliv
 
Spissing av markedsføringen av Trøndelag, v. Trøndelag Reiseliv
Spissing av markedsføringen av Trøndelag, v. Trøndelag ReiselivSpissing av markedsføringen av Trøndelag, v. Trøndelag Reiseliv
Spissing av markedsføringen av Trøndelag, v. Trøndelag ReiselivTrøndelag Reiseliv
 
7. naturbasert reiseliv trondheimkajakk final
7. naturbasert reiseliv   trondheimkajakk final7. naturbasert reiseliv   trondheimkajakk final
7. naturbasert reiseliv trondheimkajakk finalTrøndelag Reiseliv
 
NServiceBus introduction
NServiceBus introductionNServiceBus introduction
NServiceBus introductionBoris Tveritnev
 

Viewers also liked (9)

Wild norway
Wild norwayWild norway
Wild norway
 
Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...
Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...
Trøndelag Reiseliv - Markedsaktiviteter 2012, v/Kirsten Schultz og May Britt ...
 
DCI @ XING
DCI @ XINGDCI @ XING
DCI @ XING
 
Abstinence as programming practice
Abstinence as programming practiceAbstinence as programming practice
Abstinence as programming practice
 
Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...
Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...
Markedsføringen av Norge i utlandet, spissing av kommunikasjonskonsept. v. St...
 
Spissing av markedsføringen av Trøndelag, v. Trøndelag Reiseliv
Spissing av markedsføringen av Trøndelag, v. Trøndelag ReiselivSpissing av markedsføringen av Trøndelag, v. Trøndelag Reiseliv
Spissing av markedsføringen av Trøndelag, v. Trøndelag Reiseliv
 
7. naturbasert reiseliv trondheimkajakk final
7. naturbasert reiseliv   trondheimkajakk final7. naturbasert reiseliv   trondheimkajakk final
7. naturbasert reiseliv trondheimkajakk final
 
Vietējais saturs
Vietējais satursVietējais saturs
Vietējais saturs
 
NServiceBus introduction
NServiceBus introductionNServiceBus introduction
NServiceBus introduction
 

Similar to Dependency Injection (DI) Explained

Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...DicodingEvent
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckTheo Jungeblut
 
What is the best approach to tdd
What is the best approach to tddWhat is the best approach to tdd
What is the best approach to tddLuca Mattia Ferrari
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofacmeghantaylor
 
Dependency Injection in .NET
Dependency Injection in .NETDependency Injection in .NET
Dependency Injection in .NETssusere19c741
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampTheo Jungeblut
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecturekhushbu thakker
 
Node.js Service - Best practices in 2019
Node.js Service - Best practices in 2019Node.js Service - Best practices in 2019
Node.js Service - Best practices in 2019Olivier Loverde
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Theo Jungeblut
 
Continuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case StudyContinuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case StudyKamil Kochański
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplateStanislav Petrov
 
Microservices - Yet another buzzword
Microservices - Yet another buzzwordMicroservices - Yet another buzzword
Microservices - Yet another buzzwordOvidiu Dimulescu
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the CloudSimona Cotin
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database RefactoringAnton Keks
 
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUGContinuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUGJakub Pyda
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0Michael Vorburger
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practiceintive
 
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with NinjectOleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with NinjectOleksandr Valetskyy
 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as CodeQAware GmbH
 

Similar to Dependency Injection (DI) Explained (20)

Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
 
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group OsnabrueckCut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
 
What is the best approach to tdd
What is the best approach to tddWhat is the best approach to tdd
What is the best approach to tdd
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
Dependency Injection in .NET
Dependency Injection in .NETDependency Injection in .NET
Dependency Injection in .NET
 
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code CampCut your Dependencies - Dependency Injection at Silicon Valley Code Camp
Cut your Dependencies - Dependency Injection at Silicon Valley Code Camp
 
Create first android app with MVVM Architecture
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecture
 
Node.js Service - Best practices in 2019
Node.js Service - Best practices in 2019Node.js Service - Best practices in 2019
Node.js Service - Best practices in 2019
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
 
Continuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case StudyContinuous delivery with Spring Cloud Pipelines Case Study
Continuous delivery with Spring Cloud Pipelines Case Study
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Microservices - Yet another buzzword
Microservices - Yet another buzzwordMicroservices - Yet another buzzword
Microservices - Yet another buzzword
 
Deploy Angular to the Cloud
Deploy Angular to the CloudDeploy Angular to the Cloud
Deploy Angular to the Cloud
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database Refactoring
 
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUGContinuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
Continuous Delivery with Spring Cloud Pipelines: Case study. - Lublin JUG
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
Developer Job in Practice
Developer Job in PracticeDeveloper Job in Practice
Developer Job in Practice
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
 
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with NinjectOleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as Code
 

Recently uploaded

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

Dependency Injection (DI) Explained

Editor's Notes

  1. Code example 1
  2. Code example 2
  3. Code example 3