Slide 1

Slide 1 text

Dependency Injection An overview Jason Ragsdale – DPUG 4/13/2010

Slide 2

Slide 2 text

Basics ● DI is a technique for supplying an external dependency to a software component ● DI involves at least three elements ● A dependent ● Dependencies ● An injector (provider / container)

Slide 3

Slide 3 text

Our Interface

Slide 4

Slide 4 text

Highly coupled dependency

Slide 5

Slide 5 text

Manually-injected dependency

Slide 6

Slide 6 text

Framework-managed dependency injection

Slide 7

Slide 7 text

Benefits and Drawbacks ● Reduction of boiler-plate code ● Flexibility in changing out external dependencies ● Testing in general, ability to inject mock or dev dependencies

Slide 8

Slide 8 text

Types of DI ● Interface Injection ● in which the exported module provides an interface that its users must implement in order to get the dependencies at runtime. ● Setter Injection ● in which the dependent module exposes a setter method that the framework uses to inject the dependency. ● Constructor Injection ● in which the dependencies are provided through the class constructor.

Slide 9

Slide 9 text

References ● http://en.wikipedia.org/wiki/Dependency_injection ● http://martinfowler.com/articles/injection.html