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
}
}