ioc introduction
DESCRIPTION
Inversion of control, dependency injection, service locatorTRANSCRIPT
SharePoint Patterns & Practices
IoC, DI, Service LocatorHa Doan
Agenda
1. Inversion of Control (IoC) 2. Dependency Injection (DI)3. Service Locator4. Discussion5. Demo6. Service Locator in Sharepont 20107. Service Locator in Domea
• The main control of the program was inverted, moved away from you to the framework.
• In Console app:print "enter your name"read nameprint "enter your address"read addressetc...store in database
Inversion of Control (IoC)
• GUI Appwhen the user types in field a, store it in NAMEwhen the user types in field b, store it in ADDRESSwhen the user clicks the save button, call StoreInDatabase
=> Control is inverted
IoC
IoC
IoC
IoC
DI
• DI is a subtype of IOC and is implemented by constructor injection, setter injection or method injection
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
DEMO
1. Setup IoC Container2. Register services (components)3. Using components
Discusstion: Why DI & Service Locator????
• 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 serviceIService1 service1 = serviceLocator.GetInstance<IService1>();
Sharepoint Service Locator
Questions
Thank you!