web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Generic plugin - getting context object without registering for events

(0) ShareShare
ReportReport
Posted on by

Hi, i've been asked to investigate creating a generic plugin. i understand that plugins are "generic" and the steps tie the plugin to various Dynamics operations.

what we want is to be able to add new steps to entities and not change the plugin code. the plugin will handle all events the same - call a web service passing the entity name, username and record GUID to the web service.

the problem is how do i get the context info from the function that CALLS the base.registeredevents.add.... code? if i add an event handler for a specific entity i can tell it to execute a function with a signature like this:

public void ExecutePluginLogic(IServiceProvider serviceProvider)
{
// Use a 'using' statement to dispose of the service context properly
// To use a specific early bound entity replace the 'Entity' below with the appropriate class type
using (var localContext = new LocalPluginContext<Entity>(serviceProvider))
{
// Todo: Place your logic here for the plugin
throw new InvalidPluginExecutionException("***SPECIFIC - I HAVE BEEN CALLED!*********");


}
}

and can then access the context information via  LocalPluginContext.

but to be able to call this function which is passed the serviceProvider, it needs to be added in the calling code via:

    base.RegisteredEvents.Add(new PluginEvent()
            {
                Stage = eStage.PostOperation,
                MessageName = MessageNames.Create,
                EntityName = EntityNames.wwh_skill,
                PluginAction = ExecutePluginLogic
            });


 instead of a spefici call for each entity and message like this:

        public Genericplugin(string unsecureConfig, string secureConfig) : base(unsecureConfig, secureConfig)
        {
          
            // Register for any specific events by instantiating a new instance of the 'PluginEvent' class and registering it
            base.RegisteredEvents.Add(new PluginEvent()
            {
                Stage = eStage.PostOperation,
                MessageName = MessageNames.Create,
                EntityName = EntityNames.wwh_skill,
                PluginAction = ExecutePluginLogic
            });
           

            

            throw new InvalidPluginExecutionException("***NEW I AM THE TRUE GENERIC ONE!*********");

            //context.PrimaryEntityName
        }


i would liek something none entity /message specific eg:

        public Genericplugin(string unsecureConfig, string secureConfig) : base(unsecureConfig, secureConfig)
        {
          
       //somehow access IServiceProvider serviceProvider
using (var localContext = new LocalPluginContext<Entity>(serviceProvider))
            {
                //without having specific handlers for events/messages, i c want the context information here


            }

        }


*This post is locked for comments

I have the same question (0)
  • David Jennaway Profile Picture
    14,065 on at

    I think you're better off doing this outside the developer toolkit. You can easily create a generic plugin as a class library with references to the CRM assemblies. Then you'll need to register the plugin against whichever messages you want - you can do this programmatically by creating sdkmessageprocessingstep records like you would any other record in CRM

  • ashlega Profile Picture
    34,477 on at

    There is an example of "generic" plugin here:

    msdn.microsoft.com/.../gg594416.aspx

    Just like David wrote, using the toolkit might not be the best option in your scenario.

  • Suggested answer
    Community Member Profile Picture
    on at

    thanks David. Sounds like a plan!

  • Suggested answer
    Community Member Profile Picture
    on at

    thanks Alex, i;ll give this a go!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans