2. Definition:
High level modules should not depend on low level modules. Both should
depend on abstractions.
Abstractions should not depend on details. Details should depend on
abstractions.
3. Inversion of control
In software engineering, Inversion of Control (IoC) is an abstract principle
describing an aspect of some software architecture designs in which the flow of
control of a system is inverted in comparison to procedural programming.
4. Cont.…
Also known as the Hollywood Principle
Don’t call us, we’ll call you!
Objects rely on their environment to provide dependencies rather than actively
obtaining them.
Inversion of Control can make the difference between a library and a framework.
5. Dependency Injection (DI):
A design pattern in object-oriented computer programming whose purpose is to
reduce the coupling between software components.
With DI, the object does not need to know in advance about how the other part
of the system works.
6. The Service Locator Pattern
A design pattern used in software development to summarize the processes
involved in obtaining a service with a strong abstraction layer. This uses a central
registry known as the "service locator" which on request returns the information
necessary to perform a certain task.
9. What is a DI (IoC) Container?
Creates objects that are ready for you to use
Knows how to create objects and their dependencies
Knows how to initialize objects when they are created (if necessary)
Provide lifecycle support
A container is nothing more than a fancy dictionary of interfaces and their implementing types
Inversion Of Control containers act like “super factories”
10. DI Containers
Spring Framework
Unity (Microsoft)
Windsor (Castle Project)
Ninject
StructureMap
15. Dependency Injection (Pros):
Loosely Coupled
Increases Testability (A LOT!)
Separates components cleanly
Allows for use of Inversion of Control Container
16. Dependency Injection (Cons):
Increases code complexity
Can Complicate Debugging at First
Complicates following Code Flow
Architecture is less straight-forward
Overkill for smaller or throwaway applications
Easy to abuse
Be careful to avoid “XML Hell” in configuration files