Download - Dependency Injection And Ioc Containers
![Page 1: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/1.jpg)
Dependency Injection And IOC Containers
Tim MurphyTechnical Specialist - PSC Group, LLC
![Page 2: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/2.jpg)
The Pursuit of the Loosely Coupled
System
![Page 3: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/3.jpg)
Traditional Object Structure
Entity-Database Access Service- Service Proxy- Logging Service- Etc..
Database Access Service
Service Proxy
Logging Service
Tightly coupled services!
![Page 4: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/4.jpg)
• Doesn’t promote reusability
•Creates brittle systems
•Difficult to “mock” makes testing difficult
![Page 5: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/5.jpg)
With Dependency Injection
![Page 6: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/6.jpg)
The End(or is it)
![Page 7: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/7.jpg)
Better….
… but still a lot of work There are so many
dependencies in this system, how do I manage them all?
![Page 8: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/8.jpg)
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
![Page 9: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/9.jpg)
I want to spend my day writing functional business code, NOT a bunch of plumbing code…
![Page 10: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/10.jpg)
Dependency Injection Frameworks to the Rescue!
•Structure Map•Ninject•Windsor •Microsoft Unity
![Page 11: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/11.jpg)
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…”
![Page 12: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/12.jpg)
DEMO TIME!
![Page 13: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/13.jpg)
Related Topics
• Microsoft Provider Model• Microsoft Extensibility Framework (MEF)
![Page 14: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/14.jpg)
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
![Page 15: Dependency Injection And Ioc Containers](https://reader035.vdocuments.site/reader035/viewer/2022062303/55625597d8b42aa02d8b5367/html5/thumbnails/15.jpg)
Some helpful links…
• DI/IOC Frameworks:– Ninject.org– StructureMap.Sourceforge.net– www.castleproject.org/container/index.html– Unity (tinyurl.com/cm9pe3)