Dynamix Academy

The Perfect Experience to learn Microsoft Dynamics 365

Dynamics 365 CRM Plugin basics IPlugin.Execute IServiceProvicer Depth

In this article by Dynamix Academy we will learn about Microsoft Dynamics 365 CRM Plugin basics, IPlugin.Execute, IServiceProvicer , Depth , Target – Explained

  • What is a Plugin?
  • What is IPlugin and IServiceProvider while writing a plugin?
  • How data context is passed in a Plugin?
  • What is Plugin Context, Target, Depth and other important properties while developing a plugin?
  • How to get other useful objects from IServiceProvider?

What is a Plugin? Dynamics 365 CRM Plugin basics

A plug-in is a custom business logic that integrates with Microsoft Dynamics CRM to modify or extend the standard behavior of the platform. Plug-ins act as event handlers and are registered to execute on a particular event in CRM. Plugins are written in either C# or VB and can run either in synchronous or asynchronous mode.

What is IPlugin and IServiceProvider while writing a plugin?

Implement the IPlugin Interface and you will get an Execute method with the IserviceProvider interface object as a parameter. When implementing IPlugin, the class should be stateless. This is because the platform caches a class instance and re-uses it for performance reasons. The Execute method accepts a single IServiceProvider parameter. The IServiceProvider has a single method: GetService. You will use this method to get several different types of services that you can use in your code.

public void Execute(IServiceProvider serviceProvider) 

IServiceProvide is a common interface not specific to Dynamics that defined just one method:

object GetService( Type serviceType )
  • Execute method: This method runs as an entry point for any plugin in Microsoft Dynamic CRM.
  • IserviceProvider interface: This interface provides access to various services of dynamic, this interface has a method called GetService() that uses the reflection feature of .NET and allows us to get any type of service we want.

Pass configuration data to your plug-in

When you register a plug-in you have the ability to pass configuration data to it. Configuration data allows you to define how a specific instance of a registered plug-in should behave. This information is passed as string data to parameters in the constructor of your class. There are two parameters: unsecure and secure. Use the first unsecure parameter for data that you don’t mind if people can see. Use the second secure parameter for sensitive data.

The following code shows the three possible signatures for a plug-in class named SamplePlugin.

public SamplePlugin()  
public SamplePlugin(string unsecure)  
public SamplePlugin(string unsecure, string secure)

The secure configuration data is stored in a separate entity which only system administrators have privileges to read

Also find More on Dynamix Academy :

Also find Dynamix Academy on:

Related Posts