SlideShare a Scribd company logo
1 
GLOBALLOGIC 
Dependency Injection& 
Comparative study of different 
containers 
Pallav.Kumar 
10/16/2014
2 
Inversion of Control 
It is a programming technique in which the object coupling is bound at runtime by a container and is not known at compile. 
In lay-man terms it is the capability of a consumer to consume a component without knowing in advance the specifics/origins of the consumed 
component. 
IOC can be achieved by Dependency injection or Service locator. 
Dependency is just another object your class needs to function. E.g. Model class has dependency on db object. Dependency injection means 
dependency is pushed inside a class from outside. You should not be instantiating the dependencies using new operator inside a class, instead 
take it as a constructor parameter or a setter. 
It is different from factory class, as the factory class knows about the consumed class breaks this abstraction and the plug and play feature. 
When to use dependency injection? 
 Very effective at assembling loosely coupled components, and at configuring these components. 
 Ability to specify component dependencies at run time. 
 Simplified management of cross-cutting concerns. 
 Increased testability of individual components. 
 Need for pluggable architecture.
3 
Implementing Dependency Injection 
DI is a way of implementing IOC. In DI we have four broader ways of implementing the same: 
Constructor Injection: Dependencies are injected through the class constructor. 
 Pass object reference in constructor itself. When the client creates the object he passes the object in the constructor while the object is 
created. 
 Not suited for client who can only use default constructors. 
Property Injection: Dependent Object exposes a “Setter” method to inject the dependency. 
 Mostly used. 
 Dependent objects are exposed through set/get methods of classes. 
 The bad point is because the objects are publicly exposed it breaks the encapsulation rule of object oriented programming. 
Interface Injection: The Service provides an interface which consumers must implement. The interface exposes specific behaviours at runtime. 
 Implement an interface from the IOC framework. 
 IOC framework will use the interface method to inject the object in the main class.
4 
Why to use 
It decouples your class construction from construction of its dependencies. 
Dependency Inversion Principle 
Code should depend on abstraction. By depending on abstraction we are decoupling our implementation from each other. High level 
modules should not depend on low level module. Both should depend on abstraction. 
Code should depend on interface that way we substitute different dependencies, we decouple our code from lower level implementation. 
We get modular, cleaner, easy to modify and readable code. 
Dependency Injection Pros & Cons 
Pros 
Loosely Coupled & Highly Cohesive. 
Increased Testability & Maintainability. 
Flexibility of run time configuration. 
Inversions of Control containers do the wiring for you. 
Cons 
Increased code complexity. 
Can complicate debugging during the learning curve. 
Code flow becomes non-trivial. 
For class we need to figure out what are its dependencies and how to instantiate the dependencies. 
Dependency injection container 
It is a map of dependencies that your class needs with logic to create those dependencies if they have not created yet. Every time you ask for a 
dependency, the map will figure out which dependency to use, the container will check to see if it has created one of those dependencies 
already, it has it will return that otherwise it will create dependency, store it and return it.
5 
Instead of creating classes yourself you ask for container for new instance. Container can resolve complex dependencies transparently. If you 
need to swap out generic dependency, you need to update the container. 
Dependency injection Containers Benchmark - Performance comparison 
Performance Configuration Features Environment 
Container Code XML Auto Auto 
wiring 
Custom 
lifetimes 
Interception Auto 
diagnostics 
.NET SL WP7 WP8 WinRT 
AutoFac Average Yes Yes Yes Yes No Yes No Yes Yes Yes Yes Yes 
Caliburn.Micro Average Yes No No Yes No No No Yes Yes Yes Yes Yes 
Catel Average Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes 
DryIoc Fast Yes No No Yes Yes No No Yes No No No No 
Dynamo Fast Yes No Yes Yes Yes No No Yes No No No No 
fFastInjector Fast Yes No No Yes No No No Yes Yes Yes No Yes 
HaveBox Fast Yes No No Yes No Yes No Yes Yes Yes Yes No 
Hiro Fast Yes No No Yes No No No Yes No No No No 
IfInjector Fast Yes No No Yes No No No Yes Yes Yes No Yes 
LightCore Average Yes Yes Yes Yes Yes No No Yes Yes No No No 
LightInject Fast Yes No Yes Yes Yes Yes No Yes Yes No Yes Yes 
Maestro Average Yes No No Yes Yes Yes No Yes Yes Yes Yes Yes 
MEF Slow Yes No No Yes No No No Yes Yes No No Yes
6 
MEF2 Fast Yes No No Yes No No No Yes No Yes Yes Yes 
Ninject Slow Yes Yes Yes Yes Yes No No Yes Yes Yes No Yes 
Petite Fast Yes No No No No No No Yes No No No No 
SimpleInjector Fast Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes 
Speedioc Fast Yes No No No No No No Yes No No No No 
Spring.NET Very slow No Yes No Yes No Yes No Yes No No No No 
Stiletto Average Yes No No Yes No No No Yes Yes Yes Yes No 
StructureMap Average Yes Yes Yes Yes Yes Yes Yes Yes No Yes No Yes 
StyleMVVM Fast Yes No Yes Yes Yes No No Yes No No Yes No 
TinyIoc Average Yes No No Yes Yes No No Yes Yes Yes No No 
Unity Average Yes Yes Yes Yes Yes Yes No Yes Yes No Yes Yes 
Windsor Average Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No 
Ninject is definitely the slowest container. MEF and Spring.NET are faster than Ninject, but still pretty slow. AutoFac, Catel and Windsor come 
next, followed by StructureMap, Unity and LightCore. A disadvantage of Spring.NET is, that can only be configured with XML. 
DryIoc, LightInject and SimpleInjector offer a very performance combined with support for advanced scenarios like interception and generic 
decorators. Simple Injector and LightInject also provide extensive documentation and support all important platforms.

More Related Content

PPTX
Choosing an IoC container
PPTX
Continuous Integration in Action
PPTX
Seeding a Tree in a Gherkin
PPTX
Dependency Injection and Autofac
PPT
Points.com fisheye crucible code reviews 2011
PDF
Barcamp Bangkhen :: Robot Framework
PDF
Crucible Product Overview
PDF
Crucible
Choosing an IoC container
Continuous Integration in Action
Seeding a Tree in a Gherkin
Dependency Injection and Autofac
Points.com fisheye crucible code reviews 2011
Barcamp Bangkhen :: Robot Framework
Crucible Product Overview
Crucible

What's hot (20)

PPTX
Dependency Injection And Ioc Containers
PDF
Robot Framework Introduction & Sauce Labs Integration
PDF
Continuous Integration
PPTX
Acceptance Test Driven Development and Robot Framework
PPTX
Robot Framework : Lord of the Rings By Asheesh M
PPTX
Next Level Unit Testing - Javacro 2019 - Dominik Poljak
PPT
Dependency Injection & IoC
PPTX
Spring framework & inversion of control
PPTX
Dynamic Security Analysis & Static Security Analysis for Android Apps.
PDF
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
PPTX
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
PDF
Robot framework - Lord of the Rings
PPTX
Cypress test techniques cucumber bdd framework,tdd,api tests course
PPTX
What do you need to test API's?
PDF
Android talks #08 dagger2
PDF
Continuous Testing Meets the Classroom at Code.org
PPT
Java frameworks
PPTX
Top spring interview question and answer
PDF
Automated testing in javascript
PPTX
Betsson wallet & teamcity
Dependency Injection And Ioc Containers
Robot Framework Introduction & Sauce Labs Integration
Continuous Integration
Acceptance Test Driven Development and Robot Framework
Robot Framework : Lord of the Rings By Asheesh M
Next Level Unit Testing - Javacro 2019 - Dominik Poljak
Dependency Injection & IoC
Spring framework & inversion of control
Dynamic Security Analysis & Static Security Analysis for Android Apps.
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Robot framework - Lord of the Rings
Cypress test techniques cucumber bdd framework,tdd,api tests course
What do you need to test API's?
Android talks #08 dagger2
Continuous Testing Meets the Classroom at Code.org
Java frameworks
Top spring interview question and answer
Automated testing in javascript
Betsson wallet & teamcity
Ad

Similar to Dependency injection& comparative study (20)

PPTX
Dependency Inversion Principle
PPTX
Dependency Injection
PDF
Dependency Injection
PPTX
Dependency injection
PPTX
IoC and Dependency Injection
PPTX
Dependency injection and inversion
PPTX
I gotta dependency on dependency injection
PPTX
Object-Relational Mapping and Dependency Injection
PPTX
Polaris presentation ioc - code conference
PPTX
Clean Code II - Dependency Injection
PDF
DIC To The Limit – deSymfonyDay, Barcelona 2014
PPTX
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
PPTX
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
PPTX
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
PPT
Dependency injection with PHP
PPTX
Dependency Injection Lightning Talk
PPTX
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
ODP
Dependency injection explained (Zbigniew Lukasiak)
PPTX
Dip(dependency inversion principle) presentation
PPTX
Inversion of Control and Dependency Injection
Dependency Inversion Principle
Dependency Injection
Dependency Injection
Dependency injection
IoC and Dependency Injection
Dependency injection and inversion
I gotta dependency on dependency injection
Object-Relational Mapping and Dependency Injection
Polaris presentation ioc - code conference
Clean Code II - Dependency Injection
DIC To The Limit – deSymfonyDay, Barcelona 2014
Clean Code II - Dependency Injection at SoCal Code Camp San Diego (07/27/2013)
Cut your Dependencies with Dependency Injection - .NET User Group Osnabrueck
Cut your Dependencies with - Dependency Injection for South Bay.NET User Grou...
Dependency injection with PHP
Dependency Injection Lightning Talk
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Dependency injection explained (Zbigniew Lukasiak)
Dip(dependency inversion principle) presentation
Inversion of Control and Dependency Injection
Ad

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
MIND Revenue Release Quarter 2 2025 Press Release
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25 Week I

Dependency injection& comparative study

  • 1. 1 GLOBALLOGIC Dependency Injection& Comparative study of different containers Pallav.Kumar 10/16/2014
  • 2. 2 Inversion of Control It is a programming technique in which the object coupling is bound at runtime by a container and is not known at compile. In lay-man terms it is the capability of a consumer to consume a component without knowing in advance the specifics/origins of the consumed component. IOC can be achieved by Dependency injection or Service locator. Dependency is just another object your class needs to function. E.g. Model class has dependency on db object. Dependency injection means dependency is pushed inside a class from outside. You should not be instantiating the dependencies using new operator inside a class, instead take it as a constructor parameter or a setter. It is different from factory class, as the factory class knows about the consumed class breaks this abstraction and the plug and play feature. When to use dependency injection?  Very effective at assembling loosely coupled components, and at configuring these components.  Ability to specify component dependencies at run time.  Simplified management of cross-cutting concerns.  Increased testability of individual components.  Need for pluggable architecture.
  • 3. 3 Implementing Dependency Injection DI is a way of implementing IOC. In DI we have four broader ways of implementing the same: Constructor Injection: Dependencies are injected through the class constructor.  Pass object reference in constructor itself. When the client creates the object he passes the object in the constructor while the object is created.  Not suited for client who can only use default constructors. Property Injection: Dependent Object exposes a “Setter” method to inject the dependency.  Mostly used.  Dependent objects are exposed through set/get methods of classes.  The bad point is because the objects are publicly exposed it breaks the encapsulation rule of object oriented programming. Interface Injection: The Service provides an interface which consumers must implement. The interface exposes specific behaviours at runtime.  Implement an interface from the IOC framework.  IOC framework will use the interface method to inject the object in the main class.
  • 4. 4 Why to use It decouples your class construction from construction of its dependencies. Dependency Inversion Principle Code should depend on abstraction. By depending on abstraction we are decoupling our implementation from each other. High level modules should not depend on low level module. Both should depend on abstraction. Code should depend on interface that way we substitute different dependencies, we decouple our code from lower level implementation. We get modular, cleaner, easy to modify and readable code. Dependency Injection Pros & Cons Pros Loosely Coupled & Highly Cohesive. Increased Testability & Maintainability. Flexibility of run time configuration. Inversions of Control containers do the wiring for you. Cons Increased code complexity. Can complicate debugging during the learning curve. Code flow becomes non-trivial. For class we need to figure out what are its dependencies and how to instantiate the dependencies. Dependency injection container It is a map of dependencies that your class needs with logic to create those dependencies if they have not created yet. Every time you ask for a dependency, the map will figure out which dependency to use, the container will check to see if it has created one of those dependencies already, it has it will return that otherwise it will create dependency, store it and return it.
  • 5. 5 Instead of creating classes yourself you ask for container for new instance. Container can resolve complex dependencies transparently. If you need to swap out generic dependency, you need to update the container. Dependency injection Containers Benchmark - Performance comparison Performance Configuration Features Environment Container Code XML Auto Auto wiring Custom lifetimes Interception Auto diagnostics .NET SL WP7 WP8 WinRT AutoFac Average Yes Yes Yes Yes No Yes No Yes Yes Yes Yes Yes Caliburn.Micro Average Yes No No Yes No No No Yes Yes Yes Yes Yes Catel Average Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes DryIoc Fast Yes No No Yes Yes No No Yes No No No No Dynamo Fast Yes No Yes Yes Yes No No Yes No No No No fFastInjector Fast Yes No No Yes No No No Yes Yes Yes No Yes HaveBox Fast Yes No No Yes No Yes No Yes Yes Yes Yes No Hiro Fast Yes No No Yes No No No Yes No No No No IfInjector Fast Yes No No Yes No No No Yes Yes Yes No Yes LightCore Average Yes Yes Yes Yes Yes No No Yes Yes No No No LightInject Fast Yes No Yes Yes Yes Yes No Yes Yes No Yes Yes Maestro Average Yes No No Yes Yes Yes No Yes Yes Yes Yes Yes MEF Slow Yes No No Yes No No No Yes Yes No No Yes
  • 6. 6 MEF2 Fast Yes No No Yes No No No Yes No Yes Yes Yes Ninject Slow Yes Yes Yes Yes Yes No No Yes Yes Yes No Yes Petite Fast Yes No No No No No No Yes No No No No SimpleInjector Fast Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Speedioc Fast Yes No No No No No No Yes No No No No Spring.NET Very slow No Yes No Yes No Yes No Yes No No No No Stiletto Average Yes No No Yes No No No Yes Yes Yes Yes No StructureMap Average Yes Yes Yes Yes Yes Yes Yes Yes No Yes No Yes StyleMVVM Fast Yes No Yes Yes Yes No No Yes No No Yes No TinyIoc Average Yes No No Yes Yes No No Yes Yes Yes No No Unity Average Yes Yes Yes Yes Yes Yes No Yes Yes No Yes Yes Windsor Average Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No Ninject is definitely the slowest container. MEF and Spring.NET are faster than Ninject, but still pretty slow. AutoFac, Catel and Windsor come next, followed by StructureMap, Unity and LightCore. A disadvantage of Spring.NET is, that can only be configured with XML. DryIoc, LightInject and SimpleInjector offer a very performance combined with support for advanced scenarios like interception and generic decorators. Simple Injector and LightInject also provide extensive documentation and support all important platforms.