Inversion of Control - Introduction and Best Practice

3,585 views

Published on

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.

Published in: Technology, Spiritual, Business
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,585
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
176
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Inversion of Control - Introduction and Best Practice

  1. 1. Inversion of Control – Introduction & Best PracticeLars-Erik KindbladSenior ConsultantBlog: kindblad.com
  2. 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. 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
  4. 4. Traditional CodeInversion of Control | Sector, Alliance, Offering
  5. 5. Traditional CodeInversion of Control Code | Sector, Alliance, Offering
  6. 6. Traditional Code | Sector, Alliance, Offering
  7. 7. Dependency Injection - Constructor Injection | Sector, Alliance, Offering
  8. 8. Dependency Injection - Interface Injection | Sector, Alliance, Offering
  9. 9. Dependency Injection - Setter Injection | Sector, Alliance, Offering
  10. 10. Static Service Locator | Sector, Alliance, Offering
  11. 11. Injected Service Locator | Sector, Alliance, Offering
  12. 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. 13. Inversion of Control Container Manual approach Using an IOC Container | Sector, Alliance, Offering
  14. 14. | Sector, Alliance, Offering
  15. 15. Which patterns to use
  16. 16. Traditional Code | Sector, Alliance, Offering
  17. 17. Traditional Code | Sector, Alliance, Offering
  18. 18. Dependency Injection - Constructor Injection | Sector, Alliance, Offering
  19. 19. Dependency Injection - Constructor Injection | Sector, Alliance, Offering
  20. 20. Dependency Injection - Interface Injection | Sector, Alliance, Offering
  21. 21. Dependency Injection - Interface Injection | Sector, Alliance, Offering
  22. 22. Dependency Injection - Setter Injection | Sector, Alliance, Offering
  23. 23. Dependency Injection - Setter Injection | Sector, Alliance, Offering
  24. 24. Static Service Locator | Sector, Alliance, Offering
  25. 25. Static Service Locator | Sector, Alliance, Offering
  26. 26. Injected Service Locator | Sector, Alliance, Offering
  27. 27. Injected Service Locator | Sector, Alliance, Offering
  28. 28. When to use which patterns | Sector, Alliance, Offering
  29. 29. Always use Dependency Injection – Constructor Injection ...except | Sector, Alliance, Offering
  30. 30. FACADE CLASSES | Sector, Alliance, Offering
  31. 31. Facade Classes | Sector, Alliance, Offering
  32. 32. Dependency Injection | Sector, Alliance, Offering
  33. 33. Dependency Injection | Sector, Alliance, Offering
  34. 34. Service Locator | Sector, Alliance, Offering
  35. 35. Service Locator | Sector, Alliance, Offering
  36. 36. LOOPS | Sector, Alliance, Offering
  37. 37. Loops | Sector, Alliance, Offering
  38. 38. Dependency Injection | Sector, Alliance, Offering
  39. 39. Dependency Injection | Sector, Alliance, Offering
  40. 40. Service Locator | Sector, Alliance, Offering
  41. 41. Service Locator | Sector, Alliance, Offering
  42. 42. Dependency Injection using Func<> | Sector, Alliance, Offering
  43. 43. Dependency Injection using Func<> | Sector, Alliance, Offering
  44. 44. BASE CLASSES | Sector, Alliance, Offering
  45. 45. Base Classes | Sector, Alliance, Offering
  46. 46. Dependency Injection | Sector, Alliance, Offering
  47. 47. Dependency Injection | Sector, Alliance, Offering
  48. 48. Service Locator | Sector, Alliance, Offering
  49. 49. Service Locator | Sector, Alliance, Offering
  50. 50. UNKNOWN TYPES AT COMPILE TIME | Sector, Alliance, Offering
  51. 51. Unknown types at compile time | Sector, Alliance, Offering
  52. 52. Unknown types at compile time | Sector, Alliance, Offering
  53. 53. Service Locator | Sector, Alliance, Offering
  54. 54. Service Locator | Sector, Alliance, Offering
  55. 55. Summary Constructor Injection Injected Service LocatorFacade classes X(WCF Services,MVC Controllers)Loops X (Func<>) XBase classes XUnknown types at Xcompile timeAll other scenarios X | Sector, Alliance, Offering
  56. 56. QUESTIONS? | Sector, Alliance, Offering
  57. 57. www.capgemini.comThe information contained in this presentation is proprietary. ©2010 Capgemini. All rights reserved

×