Service Providers in MS CRM

Basically, Execute method gets invoked when we register a plugin, with events like Create or Update. This execute method contains service provider parameter which provides us the useful information about the execution of a plugin. Let’s get started, what are all the information can be provided by the service provider...

IServiceProvider is a container which contains service objects. 
1. IPluginExecutionContext
2. ITracingService
3. IOrganizationServiceFactory

IPluginExecutionContext is most useful out of the three. It provides contextual information of plugin during run-time. Contains information at the run-time environment that the plugin executing in, details about the user who triggered the plugin and execution pipeline. 

Syntax:
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

IOrganizationServiceFactory... allows us to create an instance of the organization. Its a factory for creating IOrganizationService instances. 

Syntax: 
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

ITracingService...allows to log plug-in run-time information, to trace the plugin execution flow and variable debugging purpose.

No comments:

Post a Comment