dependency injection and ioc containers

16
Dependency Injection And IOC Containers Tim Murphy Technical Specialist - PSC Group, LLC

Upload: tim-murphy

Post on 25-May-2015

2.277 views

Category:

Technology


1 download

DESCRIPTION

These slides are from my presentation at the January 2010 Chicago Architects Group meeting on Dependency Injection and Inversion of Control Containers

TRANSCRIPT

Page 1: Dependency Injection And Ioc Containers

Dependency Injection And IOC Containers

Tim MurphyTechnical Specialist - PSC Group, LLC

Page 2: Dependency Injection And Ioc Containers

The Pursuit of the Loosely Coupled

System

Page 3: Dependency Injection And Ioc Containers

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

• Doesn’t promote reusability

•Creates brittle systems

•Difficult to “mock” makes testing difficult

Page 5: Dependency Injection And Ioc Containers

With Dependency Injection

Page 6: Dependency Injection And Ioc Containers

The End(or is it)

Page 7: Dependency Injection And Ioc Containers

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

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

I want to spend my day writing functional business code, NOT a bunch of plumbing code…

Page 10: Dependency Injection And Ioc Containers

Dependency Injection Frameworks to the Rescue!

•Structure Map•Ninject•Windsor •Microsoft Unity

Page 11: Dependency Injection And Ioc Containers

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

DEMO TIME!

Page 13: Dependency Injection And Ioc Containers

Related Topics

• Microsoft Provider Model• Microsoft Extensibility Framework (MEF)

Page 14: Dependency Injection And Ioc Containers

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

Some helpful links…

• DI/IOC Frameworks:– Ninject.org– StructureMap.Sourceforge.net– www.castleproject.org/container/index.html– Unity (tinyurl.com/cm9pe3)

Page 16: Dependency Injection And Ioc Containers

http://geekswithblogs.net/[email protected]

Twitter: twmurph