+ All Categories
Home > Technology > Dependency Inversion Principle

Dependency Inversion Principle

Date post: 10-May-2015
Category:
Upload: tom-philip
View: 1,117 times
Download: 0 times
Share this document with a friend
Description:
Covering DI, the D of SOLID. IOC tools, TDD and a bit of best practice
Popular Tags:
16
@tommysqueak http://tomphilip.me http://lifetuned.com http://pikpak.me Dependency Inversion
Transcript
Page 1: Dependency Inversion Principle

@tommysqueak http://tomphilip.me

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

Dependency Inversion

Page 2: Dependency Inversion Principle

About• Dependency Injection

• Service Location

• TDD & Mocking - How they play together nicely

• Auto-mocking

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

Page 3: Dependency Inversion Principle
Page 4: Dependency Inversion Principle

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.

Page 5: Dependency Inversion Principle

Design Patterns

Dependency Injection

Service Locator

Page 6: Dependency Inversion Principle

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

Page 7: Dependency Inversion Principle

Demo

Page 8: Dependency Inversion Principle

Benefits•Loose coupling

•Re-use

•Testability

Page 9: Dependency Inversion Principle

Inversion of Control

Page 10: Dependency Inversion Principle

Provide

Dependency Injection

Service Locator

Page 11: Dependency Inversion Principle

Usage

•Registration

•Entry Point

Page 12: Dependency Inversion Principle

Demo

Page 13: Dependency Inversion Principle

Frameworks• AutoFac

• NInject

• Castle Windsor

• StructureMap

• Unity

Page 14: Dependency Inversion Principle

How They Look

Page 15: Dependency Inversion Principle

A Little Best Practice• Internal code should not reference

the container directly

• Verify registration with tests

• Constructor Injection over Setter Injection over Service Location

Page 16: Dependency Inversion Principle

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


Recommended