The Easy Lif Inversion of Control with Structur Brad Tutterow www.twitter.com/codebadger www.smips.com/smip/blogs/ codebadger
May 10, 2015
The Easy LifeInversion of Control with StructureMap
Brad Tutterow
www.twitter.com/codebadger
www.smips.com/smip/blogs/codebadger
What is a dependency?
Any thing the code I’m working on needs to work that is not the code I’m working
on
Database File System Web Content
Services Email Other Code
Our Problem SpaceTIME TO USE YOUR IMAGINATION
Get the current market price for a sprocket
Check for a quantity discount
Return the final price
Get the current market price for a sprocket
Call the Sprocket Market web service
Check for a quantity discount
Look it up in the sales database
Return the final price
Multiply the discount price by the quantity requested
“High-level modules should not depend on low-level modules. Both should depend on
abstractions.”
Dependency Inversion Principle
“High-level modules should not depend on low-level modules. Both should depend on
abstractions.”
Are dependencies bad?
Photo Credit
Rigidity
Photo Credit
FragilityFragility
Photo Credit
Immobility
Photo Credit
“High-level modules should not depend on low-level modules. Both should depend on
abstractions.”
Dependency Inversion Principle
SprocketStore
SalesDatabase
SprocketStore
SalesDatabase
ISalesDatabase
Photo Credit
EasierMaintenance
Testability
Photo Credit
Here we go!
Dependency Injection
Photo Credit