Dependency Inversion Principle

Post on 10-May-2015

1,117 views 0 download

Tags:

description

Covering DI, the D of SOLID. IOC tools, TDD and a bit of best practice

transcript

@tommysqueak http://tomphilip.me

http://lifetuned.comhttp://pikpak.me

Dependency Inversion

About• Dependency Injection

• Service Location

• TDD & Mocking - How they play together nicely

• Auto-mocking

• IOC - Tools, Features, Usage, Pros/Cons, Best Practice

Definition• High-level modules should not depend

on low-level modules. Both should depend on abstractions.

• Abstractions should not depend upon details. Details should depend upon abstractions.

Design Patterns

Dependency Injection

Service Locator

StoryAs a CustomerI want to change my passwordIn order to keep my account secureScenarioGiven I’m an account holderWhen I change my passwordThen It should ensure it is a strong passwordAnd it should change my passwordAnd it should notify me it has been changed

Demo

Benefits•Loose coupling

•Re-use

•Testability

Inversion of Control

Provide

Dependency Injection

Service Locator

Usage

•Registration

•Entry Point

Demo

Frameworks• AutoFac

• NInject

• Castle Windsor

• StructureMap

• Unity

How They Look

A Little Best Practice• Internal code should not reference

the container directly

• Verify registration with tests

• Constructor Injection over Setter Injection over Service Location

Picture Credits• http://www.flickr.com/

photos/smil/4196304056/ - Patterns

• http://lostechies.com/derickbailey/2009/02/11/solid-development-principles-in-motivational-pictures/ - SOLID pictures

• http://www.flickr.com/photos/kevindean/4031083510/ - trolley

• http://www.flickr.com/photos/gcwest/281385801/ - containers