Download - IoC introduction
![Page 1: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/1.jpg)
SharePoint Patterns & Practices
IoC, DI, Service LocatorHa Doan
![Page 2: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/2.jpg)
Agenda
1. Inversion of Control (IoC) 2. Dependency Injection (DI)3. Service Locator4. Discussion5. Demo6. Service Locator in Sharepont 20107. Service Locator in Domea
![Page 3: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/3.jpg)
• 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)
![Page 4: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/4.jpg)
• 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
![Page 5: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/5.jpg)
IoC
IoC
![Page 6: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/6.jpg)
IoC
![Page 7: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/7.jpg)
DI
• DI is a subtype of IOC and is implemented by constructor injection, setter injection or method injection
![Page 8: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/8.jpg)
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
![Page 9: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/9.jpg)
DEMO
1. Setup IoC Container2. Register services (components)3. Using components
![Page 10: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/10.jpg)
Discusstion: Why DI & Service Locator????
![Page 11: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/11.jpg)
• 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
![Page 12: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/12.jpg)
Questions
![Page 13: IoC introduction](https://reader036.vdocument.in/reader036/viewer/2022082700/54c6b6ec4a79596e348b459a/html5/thumbnails/13.jpg)
Thank you!