SlideShare a Scribd company logo
Dependency Injection
What, Why and How
Ravish Chhabra
DesignRequirements
 Maintainability :- It is the quality of a software system that determines how
easily and how efficiently you can update it.
 Testability :- It enables you to effectively test individual parts of the system. In
short, how easy is to test the system. Test driven development is use to write Unit
test before writing any code to implement to improve the quality of applications.
 Flexibility and Extensibility :- How easily the system can adapt to work in
different ways is flexibility and add new features is extensibility
Definition and Types
 Coupling :- It states the dependency of the system. How dependent are sub
systems in the system.
 Tight Coupling
 Loose Coupling
 Tight Coupling :- Strong or direct dependency between components.
 Loose Coupling :- Loose or indirect dependency between components.
Tight Coupling
CustomerRepository class directly
depends upon Database class.
Loose Coupling
CustomerRepository class depends
upon IDatabase interface
DependencyInjection
 WHAT
 A Software Design Pattern that follows Dependency inversion principle and
implement Inversion of Control for the resolution of dependencies at run-
time or compile time.
 WHY
 The “D” is Dependency Injection (in SOLID principles of design) used to
achieve Loose Coupling in the system.
Principles
 Dependency Inversion Principle:- A software design principle that provide
us guidelines to loosely couple the system.
1. High level modules should not depend on low level modules or
subsystems. Both should depend on Abstractions.
2. Abstraction should not depend on details but vice versa.
 Inversion Of Control (IOC) :- It is the mechanism that is used to implement
the Dependency Inversion principle.
Abstraction is introduced in the system to make the high level modules to
depend on abstraction rather than the sub systems themselves.
Tightly Coupled System
Forcefully you have to write to
Event Logs only.
IOC Mechanism implemented
By adding an interface( INotify )
High level module LogMonitor
using abstraction( INotify )
Still, Concrete class is initialized
To achieve further level of
Decoupling, DI is used.
 Dependency Injection injects the concrete implementation into a class ( by moving
it out of dependent class) that is using abstraction.
 Major ways of implementing DI
 Constructor Injection - pass the object of concrete class into the constructor of
dependent class.
Method Injection - pass the object of the concrete class into the method the
dependent class which is actually invoking the action.
Property Injection - pass the object of the concrete class via a setter property
that was exposed by the dependent class.
Dependency Injection Continued..
Constructor Injection
Object of concrete class
(INotify Type) will be passed into
Constructor parameter
Object of concrete class passed to
Constructor of LogMonitor
Method Injection
Object of concrete class
(INotify Type) will be passed
into Method parameter
Object of concrete class passed as
Method parameter
Other Key Concepts Of DI
 Dependency injection injects the dependencies of a class at runtime.
 DI Containers: To automatically inject dependencies we use a Dependency Injection(DI)
container. We can also inject the dependencies manually but using a DI container provides
the following benefits
 Automatic Dependency Resolution When dependendencies are managed by the
container there are less chances of error. Suppose if our application has a lot of
dependencies then injecting those dependencies is also difficult to manage if we are
injecting them without a DI container
 Decouples the client from the dependency – It saves the effort and work spent by client
to inject the dependency.
 StructureMap
 UnityContainer
 Autofac
 Ninject
 Castle Windsor
 Spring .Net
Popular DI Containers For .NET
DI Containers Example-Unity Container
Dependency configured using Container
and is resolved at run time
Pros and Cons
 PROS
 Reduced Dependencies.
 Increased Testability and Maintainability – Inject mock implementations for testing.
 More Reusable and Extensible Code – External pluggable and configurable components.
 Run Time configuration for Dependency Injection
 CONS
 Increased code complexity.
 Can complicate debugging while development.
`
Dependency injection and inversion

More Related Content

PPTX
Dependency Inversion Principle
PPTX
Dependency injection presentation
PPTX
Dependency injection - the right way
PPTX
Dependency Inversion Principle
PPTX
Dip(dependency inversion principle) presentation
PPTX
Dependency injection ppt
PPT
Angular 8
PDF
Dependency Injection
Dependency Inversion Principle
Dependency injection presentation
Dependency injection - the right way
Dependency Inversion Principle
Dip(dependency inversion principle) presentation
Dependency injection ppt
Angular 8
Dependency Injection

What's hot (20)

PPTX
C# programming language
PDF
Building blocks of Angular
PPTX
c# usage,applications and advantages
PDF
Dependency injection for beginners
PPTX
Design Pattern - Factory Method Pattern
PPT
Ionic Framework
PDF
Angular Directives
PPTX
C# language
PDF
Angular
PPTX
C sharp
PPSX
Introduction to .net framework
PPTX
C# 101: Intro to Programming with C#
PPTX
Angular 2.0 Dependency injection
PPTX
component based development model
PPTX
MVVM ( Model View ViewModel )
PDF
Angular - Chapter 1 - Introduction
DOCX
Angular Interview Questions & Answers
PPTX
Inversion of Control and Dependency Injection
PPTX
Observer Software Design Pattern
PPT
Selenium ppt
C# programming language
Building blocks of Angular
c# usage,applications and advantages
Dependency injection for beginners
Design Pattern - Factory Method Pattern
Ionic Framework
Angular Directives
C# language
Angular
C sharp
Introduction to .net framework
C# 101: Intro to Programming with C#
Angular 2.0 Dependency injection
component based development model
MVVM ( Model View ViewModel )
Angular - Chapter 1 - Introduction
Angular Interview Questions & Answers
Inversion of Control and Dependency Injection
Observer Software Design Pattern
Selenium ppt
Ad

Viewers also liked (12)

PPTX
Dependency Injection
PPTX
Dependency injection
PPTX
Dependency Injection and Autofac
PDF
Dependency Injection in .NET
PDF
Il pattern mvvm come strutturare al meglio il vostro progetto
PDF
Dependency Injection
PDF
Spring: usarlo conviene, ma usalo bene!
PPTX
Inversion of Control @ CD2008
PDF
IOC in Unity
PDF
IOC in unity
PPTX
Workshop - cqrs brief introduction
PPTX
Design Pattern Architetturali - Dependency Injection
Dependency Injection
Dependency injection
Dependency Injection and Autofac
Dependency Injection in .NET
Il pattern mvvm come strutturare al meglio il vostro progetto
Dependency Injection
Spring: usarlo conviene, ma usalo bene!
Inversion of Control @ CD2008
IOC in Unity
IOC in unity
Workshop - cqrs brief introduction
Design Pattern Architetturali - Dependency Injection
Ad

Similar to Dependency injection and inversion (20)

PPTX
Introduction to Spring Framework
 
PPTX
Test Driven Development:Unit Testing, Dependency Injection, Mocking
PPT
Dependency Injection & IoC
PPTX
Design patterns fast track
PDF
Dependency Injection
PPTX
Dependency Injection
PPTX
Dependency Injection in .NET
PPTX
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
PDF
Swiz DAO
PPT
20080531 Intro To Dependency Injection & Inversion Of Control
PDF
Dev ops and safety critical systems
PDF
Mock Objects, Design and Dependency Inversion Principle
PPTX
Integration testing.
PDF
Software Engineering Past Papers (Short Questions)
PPTX
Mobile App Architectures & Coding guidelines
PPTX
Over view of software artitecture
PPTX
Dependency Injection in Java Essential for Building Maintainable Projects in ...
PDF
Unit Testing Fundamentals
PDF
Take Your Web Development To The Next Level With These Top 2 Libraries
PPTX
I gotta dependency on dependency injection
Introduction to Spring Framework
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Dependency Injection & IoC
Design patterns fast track
Dependency Injection
Dependency Injection
Dependency Injection in .NET
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Swiz DAO
20080531 Intro To Dependency Injection & Inversion Of Control
Dev ops and safety critical systems
Mock Objects, Design and Dependency Inversion Principle
Integration testing.
Software Engineering Past Papers (Short Questions)
Mobile App Architectures & Coding guidelines
Over view of software artitecture
Dependency Injection in Java Essential for Building Maintainable Projects in ...
Unit Testing Fundamentals
Take Your Web Development To The Next Level With These Top 2 Libraries
I gotta dependency on dependency injection

Recently uploaded (20)

PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
top salesforce developer skills in 2025.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
L1 - Introduction to python Backend.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
top salesforce developer skills in 2025.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Wondershare Filmora 15 Crack With Activation Key [2025
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
How to Migrate SBCGlobal Email to Yahoo Easily
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
L1 - Introduction to python Backend.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
How Creative Agencies Leverage Project Management Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free

Dependency injection and inversion

  • 1. Dependency Injection What, Why and How Ravish Chhabra
  • 2. DesignRequirements  Maintainability :- It is the quality of a software system that determines how easily and how efficiently you can update it.  Testability :- It enables you to effectively test individual parts of the system. In short, how easy is to test the system. Test driven development is use to write Unit test before writing any code to implement to improve the quality of applications.  Flexibility and Extensibility :- How easily the system can adapt to work in different ways is flexibility and add new features is extensibility
  • 3. Definition and Types  Coupling :- It states the dependency of the system. How dependent are sub systems in the system.  Tight Coupling  Loose Coupling  Tight Coupling :- Strong or direct dependency between components.  Loose Coupling :- Loose or indirect dependency between components.
  • 4. Tight Coupling CustomerRepository class directly depends upon Database class.
  • 5. Loose Coupling CustomerRepository class depends upon IDatabase interface
  • 6. DependencyInjection  WHAT  A Software Design Pattern that follows Dependency inversion principle and implement Inversion of Control for the resolution of dependencies at run- time or compile time.  WHY  The “D” is Dependency Injection (in SOLID principles of design) used to achieve Loose Coupling in the system.
  • 7. Principles  Dependency Inversion Principle:- A software design principle that provide us guidelines to loosely couple the system. 1. High level modules should not depend on low level modules or subsystems. Both should depend on Abstractions. 2. Abstraction should not depend on details but vice versa.  Inversion Of Control (IOC) :- It is the mechanism that is used to implement the Dependency Inversion principle. Abstraction is introduced in the system to make the high level modules to depend on abstraction rather than the sub systems themselves.
  • 8. Tightly Coupled System Forcefully you have to write to Event Logs only.
  • 9. IOC Mechanism implemented By adding an interface( INotify ) High level module LogMonitor using abstraction( INotify ) Still, Concrete class is initialized To achieve further level of Decoupling, DI is used.
  • 10.  Dependency Injection injects the concrete implementation into a class ( by moving it out of dependent class) that is using abstraction.  Major ways of implementing DI  Constructor Injection - pass the object of concrete class into the constructor of dependent class. Method Injection - pass the object of the concrete class into the method the dependent class which is actually invoking the action. Property Injection - pass the object of the concrete class via a setter property that was exposed by the dependent class. Dependency Injection Continued..
  • 11. Constructor Injection Object of concrete class (INotify Type) will be passed into Constructor parameter Object of concrete class passed to Constructor of LogMonitor
  • 12. Method Injection Object of concrete class (INotify Type) will be passed into Method parameter Object of concrete class passed as Method parameter
  • 13. Other Key Concepts Of DI  Dependency injection injects the dependencies of a class at runtime.  DI Containers: To automatically inject dependencies we use a Dependency Injection(DI) container. We can also inject the dependencies manually but using a DI container provides the following benefits  Automatic Dependency Resolution When dependendencies are managed by the container there are less chances of error. Suppose if our application has a lot of dependencies then injecting those dependencies is also difficult to manage if we are injecting them without a DI container  Decouples the client from the dependency – It saves the effort and work spent by client to inject the dependency.
  • 14.  StructureMap  UnityContainer  Autofac  Ninject  Castle Windsor  Spring .Net Popular DI Containers For .NET
  • 15. DI Containers Example-Unity Container Dependency configured using Container and is resolved at run time
  • 16. Pros and Cons  PROS  Reduced Dependencies.  Increased Testability and Maintainability – Inject mock implementations for testing.  More Reusable and Extensible Code – External pluggable and configurable components.  Run Time configuration for Dependency Injection  CONS  Increased code complexity.  Can complicate debugging while development. `