Hello,
I've been reading this article in Microsoft's documentation on best practices for developing IPlugin. I'm a bit confused regarding the "stateless" requirement.
If I understand correctly, storing objects like the IPluginExecutionContext and its derivatives (e.g. IOrganizationService) is problematic because their object references might persist between executions, correct? There's also the fact that the server will cache the plugin for a certain amount of time, so it wouldn't call the constructor each time.
However, does this problem still exist if I create a class member from scratch in the Execute function, or functions called by Execute?
Let's use the following example:
public class MyPlugin : IPlugin { Entity customEntity; MyCustomObject customObject; public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); Guid id = ((Entity)context.InputParameters["Target"]).Id; customEntity = service.Retrieve("new_customentity", id, new ColumnSet()); DoStuff(); } private void DoStuff() { customObject = new MyCustomObject(); } }
In the example I posted, would customEntity (and customObject, for that matter) violate the stateless requirement of the plugin? Or would they also somehow get cached between executions?