Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependency Injection

Dependency Injection

Jason Ragsdale

April 13, 2010
Tweet

More Decks by Jason Ragsdale

Other Decks in Technology

Transcript

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

    View Slide

  2. 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)

    View Slide

  3. Our Interface

    View Slide

  4. Highly coupled dependency

    View Slide

  5. Manually-injected dependency

    View Slide

  6. Framework-managed dependency
    injection

    View Slide

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

    View Slide

  8. 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.

    View Slide

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

    View Slide