According to Microsoft's documentation on Develop IPlugin implementations as stateless:
"Because the platform caches plug-in class instances, the constructor isn't called for every invocation of plug-in execution."
However, when testing this behavior, I'm seeing different results.
Code to reproduce:
public class TestPlugin : IPlugin
{
private Guid ExecutionContextId { get; } = Guid.NewGuid();
public void Execute(IServiceProvider serviceProvider)
{
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace($"ExecutionContextId: {ExecutionContextId}");
}
}
Expected behavior: based on the documentation, the same GUID should be logged multiple times because the plugin instance should be cached and reused.
Actual behavior: each execution logs a different GUID, indicating a new instance is created each time.
Environment:
- Dataverse Online (Developer environment)
- Plugin registered in Sandbox mode
- Synchronous execution
- Tested: August 2025
What I've tried:
- Verified the plugin is registered correctly
- Tested with multiple executions in quick succession
- Checked trace logs - definitely different GUIDs each time
Question: has the plugin execution model changed in Dataverse? Is the documentation outdated, or am I misunderstanding how plugin caching works?
If instances are no longer cached, this would affect plugin design patterns significantly.