This presentation goes through what Inversion of Control is, which IOC patterns that exists, which of the patterns you should use and when you should use them.
Inversion of Control - Introduction and Best Practice
1. Inversion of Control – Introduction & Best Practice
Lars-Erik Kindblad
Senior Consultant
Blog: kindblad.com
2. Agenda
Introduction
• Inversion of Control
• Dependency Injection Patterns
• Service Locator Patterns
• Inversion of Control Containers
Best Practice
• What patterns to use
• When to use the patterns
Summary
| Sector, Alliance, Offering
3. Inversion of Control
Inversion of Control = IOC
Make code loosely coupled
Allows for more reuse
Make unit testing possible
How? Move creation of dependencies outside the class they are
being used in
A better name - Inversion of Dependency Creation
| Sector, Alliance, Offering
12. Inversion of Control Container
A framework that can automatically create a given type with all the
required dependencies
Popular frameworks
• Unity
• Castle Windsor
• Ninject
• StructureMap
• etc.
| Sector, Alliance, Offering
13. Inversion of Control Container
Manual approach
Using an IOC Container
| Sector, Alliance, Offering
55. Summary
Constructor Injection Injected Service Locator
Facade classes X
(WCF Services,
MVC Controllers)
Loops X (Func<>) X
Base classes X
Unknown types at X
compile time
All other scenarios X
| Sector, Alliance, Offering