Sorin Damian - Using and Abusing Dependency Injection Containers

Post on 02-Jul-2015

279 views 4 download

Transcript of Sorin Damian - Using and Abusing Dependency Injection Containers

Using and Abusing

Dependency Injection

ContainersSorin Damian

SC RomSoft SRL (rms.ro)

[10th of November 2012]

Why do YOU use it?

UGLY DEMO

The Inversion of Control Principle

Don’t ask for information

Ask for help

IoC – Don’t call us, we’ll call you

IoC for 5 year olds

When you go and get things out of the

refrigerator for yourself, you can cause problems.

You might leave the door open, you might get

something Mommy or Daddy doesn't want you to

have. You might even be looking for something

we don't even have or which has expired.

What you should be doing is stating a need, "I

need something to drink with lunch," and then we

will make sure you have something when you sit

down to eat. http://stackoverflow.com/questions/1638919/how-to-explain-dependency-injection-to-a-5-year-old

NICER BUT STILL

UGLY DEMO

Dependency Injection

Design pattern

The Inversion of Control principle

applied to dependency management

Ask for dependencies

Instantiating them is a separate concern

What you get

+ decupling

+ reusability

+ testability

- more code

- more ceremony

- composition hell

DEMO (15 lines container)

DEMO (using the container)

If it looks like a factory..

And it works like a factory..

Call the container only at

the composition root!

Every time you call the container to

get your dependencies a kitten dies..

Any questions?

Thank you!

Diamond Sponsors

Platinum Sponsors Gold Sponsors

Training Partners Media Partners Other Partners