inversion of control with structuremap
DESCRIPTION
Simplify your life with Inversion of Control! One of the most challenging aspects of software development is dealing with code that depends on other code. The Dependency Inversion principle tells us that we should depend on abstractions, not concretions but it doesn’t tell us how to do that. That’s where Dependency Injection comes in – we inject our dependencies into the mushy center of our classes with a big syringe. This can often be as messy as it sounds, but luckily Inversion of Control Containers can help us by providing a single source for configuring dependencies. This presentation will show how to effectively manage dependencies with StructureMap, an open-source IOC container. StructureMap can make your life easier, your code more maintainable, and the world a better place.TRANSCRIPT
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