The Zen of IoC

44
the zen of IoC [email protected]

description

An overview of Inversion of Control: what is it and, more importantly, why should anyone care?

Transcript of The Zen of IoC

Page 1: The Zen of IoC

the zen of IoC

[email protected]

Page 2: The Zen of IoC

back to basics (1968)

Page 3: The Zen of IoC

coupling: bad

Page 4: The Zen of IoC

cohesion: good

Page 5: The Zen of IoC

now, things evolve…

Page 6: The Zen of IoC

SOLID OOPMulti-layerTDDinterfacesmockingSOA

patternsFAIR

refactoring

OODframeworks

interop

polymorphism

inheritance

encapsulation

Page 7: The Zen of IoC

so, nowadays...

Page 8: The Zen of IoC

cohesion: good

Page 9: The Zen of IoC

coupling: bad

Page 10: The Zen of IoC

a subtle case of coupling

Page 11: The Zen of IoC

var repo = new UserRepository();var users = repo.GetAll();

coupling here

Page 12: The Zen of IoC

constructor coupling blues

I can’t test this thing!

What? This test hits the database?!?

But this new class implements this interface!

This refactoring will take ages…

How do I link this view and controller?

Page 13: The Zen of IoC

enter IoC

Page 14: The Zen of IoC

IoC is a concept(what)

Page 15: The Zen of IoC

DI is a pattern(how)

Page 16: The Zen of IoC

injection through construction

lifetime

dependency

concurrency safe

simplest approach

Page 17: The Zen of IoC

injection through properties

simpler

construction

flexible injection

concurrency risks

Page 18: The Zen of IoC

injection through interfaces

flexible injection

concurrency risks

equivalent to props

harder setup

Page 19: The Zen of IoC

the evil twin

Page 20: The Zen of IoC

service locator

lifecycle controlsmaller contractsconcurrency riskstesting is a b*

Page 21: The Zen of IoC

tools of the tradeCastle WindsorUnityNInjectSimpleInjector

Page 22: The Zen of IoC

consequences

Page 23: The Zen of IoC

dude, where’s my code?

Page 24: The Zen of IoC

ramping + tooling

Page 25: The Zen of IoC

smell: lots of dependencies

Page 26: The Zen of IoC

man, your code already sucks

Page 27: The Zen of IoC

risk: interfaces abound

Page 28: The Zen of IoC

grain of salt + refactoring

Page 29: The Zen of IoC

risk: locators everywhere

Page 30: The Zen of IoC

KISS

Page 31: The Zen of IoC

natural pluggable design

Page 32: The Zen of IoC

overdriven Liskov

Page 33: The Zen of IoC

easy mocking

Page 34: The Zen of IoC

great enabler for tdd

Page 35: The Zen of IoC

issue: DDD & IoC mismatch

Page 36: The Zen of IoC

no easy way out

Page 37: The Zen of IoC

interception easily doable

Page 38: The Zen of IoC

added flexibility

Page 39: The Zen of IoC

good-bye to singletons

Page 40: The Zen of IoC

let the container handle this

Page 41: The Zen of IoC

tks.

Page 42: The Zen of IoC

zen quotesBeing a spectator while one is also a participant spoils one's performance.

Everything exists in relation to other things.   

In emptiness, forms are born.  When one becomes empty of the assumptions,inferences, and judgments he has acquired over the years, he comes close to his original nature and is capable of conceiving original ideas and reacting freshly. 

Security and changelessness are fabricated by the ego-dominated mind and do not exit in nature.  To accept insecurity and commit oneself to the unknown creates a relaxing faith in the universe.     

True insight does not issue from specialized knowledge, from membership in coteries, from doctrines or dogmas.  It comes from the preconscious intuitions of one's whole being, from one's own code.

Page 44: The Zen of IoC

the tao of IoC

[email protected]