This documentation is archived and is not being maintained.

Plug-in Context

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

All plug-ins must implement the IPlugin interface. The IPlugin interface defines an Execute method, which takes an IPluginExecutionContext parameter. When a system event is fired for which a plug-in is registered, the system creates and populates the context. The system then calls the plug-in's Execute method, passing in the context as a parameter.

At run time, the execution context is passed to each registered plug-in in the pipeline when they are executed. Each plug-in in the execution pipeline is able to modify writable properties in the context. For example, given a plug-in registered for a pre-event and another plug-in registered for a post-event, the post-event plug-in can receive a context that has been modified by the pre-event plug-in. The same situation applies to plug-ins that are registered within the same stage. 

The context contains information that describes the run-time environment that the plug-in is executing in, information related to the execution pipeline, and entity business information.

IPluginExecutionContext class diagram

All the properties in the class are read-only. However, your plug-in can modify the contents of those properties that are of type PropertyBag.

There are two methods provided in IPluginExecutionContext: CreateCrmService and CreateMetadataService. We recommend that plug-in code should create an instance of the Microsoft Dynamics CRM Web services through these methods. The platform provides the correct Web service URLs and network credentials for you when you use these methods. However, do not use these methods if you are writing code for a plug-in in that is used in a child pipeline. In a child pipeline, you must instantiate the CrmService or MetadataService manually. For examples about how to call these methods, see the plug-in code provided in the SDK samples.

See Also



© 2010 Microsoft Corporation. All rights reserved.