Dependency Injection (DI)Or stop cooking spaghetti (code)
1			    “Dependency Injection                          is a key element                    of agile architecture”Ward Cunningham
Dependency Injection (DI) is not a pattern, but rather a set of tools2
DIisone of the ways to applyInversion of Control (IoC) principle3
Literally – let go off control and let someone feed you4
Example TaskObviously its time to go to code . Check out NoDI project.5
Specifications are singing rigoletto6
Specs tend to change7
Highly coupled code is a step to spaghetti code8Can’t intercept and change code;Can’t unit-test in isolation;Conceptual problems in modules design;Logic is spread across many parts.
Divide et impera9DI’s base is Interface Oriented Programming. Write your code against abstractions rather then concrete implementations.
Single Responsibility Principle (SRP)10By applying DI to class we let it “concentrate” on task it was designed for.
ModularityReplace;
Reuse;
Build in parallel;
Easier to maintain;
Easier to unit-test.Go on and check this stuff applied in PoorMansDI project.11
DI patterns.12
Composition Root13
Constructor injection14
Property (setter) injection15
Method injection16
Ambient context17
Which one to choose?18
3D of DI19
1. Composition20
2. Lifetime Management21Transient (per call);
Singleton;
Per thread;
Per web request;
Per web session;

Dependency injection

Editor's Notes