dependency injection and ioc containers
DESCRIPTION
These slides are from my presentation at the January 2010 Chicago Architects Group meeting on Dependency Injection and Inversion of Control ContainersTRANSCRIPT
Dependency Injection And IOC Containers
Tim MurphyTechnical Specialist - PSC Group, LLC
The Pursuit of the Loosely Coupled
System
Traditional Object Structure
Entity-Database Access Service- Service Proxy- Logging Service- Etc..
Database Access Service
Service Proxy
Logging Service
Tightly coupled services!
• Doesn’t promote reusability
•Creates brittle systems
•Difficult to “mock” makes testing difficult
With Dependency Injection
The End(or is it)
Better….
… but still a lot of work There are so many
dependencies in this system, how do I manage them all?
Dependency InjectionWith a Factory Pattern
Entity
“I need to be created, including have all my services crated and given to me.”
Object Factory
“ I know how to build all of this stuff.”
Application
“I need an Entity, but I don’t know how to create it.”
Create an
Entity for m
e
Create aConcrete instance
Instance forapplication
I want to spend my day writing functional business code, NOT a bunch of plumbing code…
Dependency Injection Frameworks to the Rescue!
•Structure Map•Ninject•Windsor •Microsoft Unity
With a Dependency Injection/ IOC Framework
Entity-Database Access Service- Service Proxy- Logging Service- Etc..
Container
“You ask me for objects, I create them based on my registrations”
Provider
“You tell me what type of object you want, I give you the object you need:”
Application
“I need a concrete instance of an Entity…”
DEMO TIME!
Related Topics
• Microsoft Provider Model• Microsoft Extensibility Framework (MEF)
Some helpful links…
• Martin Fowler – martinfowler.com/articles/injection.html
• MSDN Article on Dependency Injection pattern– http://tinyurl.com/bm8wm5
• Dependancey Injection tutorial– http://tinyurl.com/5fysrq
Some helpful links…
• DI/IOC Frameworks:– Ninject.org– StructureMap.Sourceforge.net– www.castleproject.org/container/index.html– Unity (tinyurl.com/cm9pe3)
http://geekswithblogs.net/[email protected]
Twitter: twmurph