Coding Multiple Plugins in One Assembly in Dynamics 365

Leave a comment

In this post we will look at how to code 2 plugins in one assembly. This might be useful if you want to keep related pieces of code under the same code base.

Let’s create a new VS project:

Rename the class to Plugins:

Add Microsoft.CrmSdk.CoreAssemblies through NuGet.

Add the code. We will add 2 functions, Plugin1 and Plugin2:

The code will write a Plugin Trace Log entry.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;

namespace Carl.MultiplePlugins
{
    public class Plugin1 : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            tracingService.Trace("Plugin 1.");
        }
    }

    public class Plugin2 : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            tracingService.Trace("Plugin 2.");
        }
    }

}

 

Sign and build the project.

Now in the Plugin Registration Tool, select the assembly to register it. We see it is picking up there are 2 plugins:

And 2 have been registered:

We see the plugins:

Right-click the first plugin to add a step:

Let’s run this on create of an Account:

And the second one, create of a Contact:

Ensure plugin tracing is turned on in System Settings.

Now create an Account.

Go to Plugin Trace Logs in Advanced Find:

Plugin 1 is written to the log:

Now create a Contact. Plugin 2 has run.

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

Your email address will not be published. Required fields are marked *