The Zen of IoC

Post on 31-Aug-2014

510 views 3 download

Tags:

description

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

Transcript of The Zen of IoC

the zen of IoC

diogo.lucas@gmail.com

back to basics (1968)

coupling: bad

cohesion: good

now, things evolve…

SOLID OOPMulti-layerTDDinterfacesmockingSOA

patternsFAIR

refactoring

OODframeworks

interop

polymorphism

inheritance

encapsulation

so, nowadays...

cohesion: good

coupling: bad

a subtle case of coupling

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

coupling here

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?

enter IoC

IoC is a concept(what)

DI is a pattern(how)

injection through construction

lifetime

dependency

concurrency safe

simplest approach

injection through properties

simpler

construction

flexible injection

concurrency risks

injection through interfaces

flexible injection

concurrency risks

equivalent to props

harder setup

the evil twin

service locator

lifecycle controlsmaller contractsconcurrency riskstesting is a b*

tools of the tradeCastle WindsorUnityNInjectSimpleInjector

consequences

dude, where’s my code?

ramping + tooling

smell: lots of dependencies

man, your code already sucks

risk: interfaces abound

grain of salt + refactoring

risk: locators everywhere

KISS

natural pluggable design

overdriven Liskov

easy mocking

great enabler for tdd

issue: DDD & IoC mismatch

no easy way out

interception easily doable

added flexibility

good-bye to singletons

let the container handle this

tks.

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.

the tao of IoC

diogo.lucas@gmail.com