The Zen of IoC
-
Upload
diogo-lucas -
Category
Technology
-
view
510 -
download
3
description
Transcript of The Zen of IoC
the zen of IoC
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.
fowler on IoC:
http://martinfowler.com/articles/injection.html
http://martinfowler.com/bliki/InversionOfControl.html
interception on SI:
http://simpleinjector.codeplex.com/wikipage?title=InterceptionExtensions
IoC x anemic DM
http://
programmers.stackexchange.com/questions/72768/does-inversion-of-control-pr
omote-anemic-domain-model
image source:
http://photopin.com
the tao of IoC