Successfully reported this slideshow.

IoC introduction


Published on

Inversion of control, dependency injection, service locator

Published in: Technology, Business
  • Be the first to comment

IoC introduction

  1. 1. SharePoint Patterns & Practices IoC, DI, Service Locator Ha Doan
  2. 2. Agenda 1. Inversion of Control (IoC) 2. Dependency Injection (DI) 3. Service Locator 4. Discussion 5. Demo 6. Service Locator in Sharepont 2010 7. Service Locator in Domea
  3. 3. • The main control of the program was inverted, moved away from you to the framework. • In Console app: print "enter your name" read name print "enter your address" read address etc... store in database Inversion of Control (IoC)
  4. 4. • GUI App when the user types in field a, store it in NAME when the user types in field b, store it in ADDRESS when the user clicks the save button, call StoreInDatabase => Control is inverted IoC
  5. 5. IoC IoC
  6. 6. IoC
  7. 7. DI • DI is a subtype of IOC and is implemented by constructor injection, setter injection or method injection
  8. 8. Service Locator The service locator pattern is a design pattern used in software development to encapsulate the processes involved in obtaining a service with a strong abstraction layer
  9. 9. DEMO 1. Setup IoC Container 2. Register services (components) 3. Using components
  10. 10. Discusstion: Why DI & Service Locator????
  11. 11. • Namespace: Microsoft.Practices.SharePoint.Common.dll • Get service locator: IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); • Add service: var typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>(); typeMappings.RegisterTypeMapping<IService1, Service1>(); • Get service IService1 service1 = serviceLocator.GetInstance<IService1>(); Sharepoint Service Locator
  12. 12. Questions
  13. 13. Thank you!