Notification Handlers Not Triggered When Plugin Is Instantiated via Factory and Mediator Is Used in Constructor Chain #1128
Unanswered
Sabari2810
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We’re encountering an issue where MediatR INotificationHandler implementations are not being triggered when a plugin is instantiated dynamically through a factory and a MediatR pipeline is triggered in the constructor call chain.
Problem Context
We have a PluginRegistrationFactory that dynamically creates plugins using:
_serviceProvider.GetRequiredService(descriptor.Manifest.RegistrationType)
The plugin constructor (or a service called in its constructor) sends a MediatR IRequest, which is handled correctly.
The handler for that request publishes a notification using IMediator.Publish(...).
The INotificationHandler for this notification is registered correctly (via RegisterServicesFromAssembly) but does not get triggered.
If the same MediatR publish logic is executed outside the factory-instantiated path (e.g., inside a controller or background task), the notification handlers are triggered correctly.
What We Tried
Verified that all handlers are registered via:
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(...))
Issue only occurs when the logic runs inside the plugin creation path via the factory.
What Doesn’t Work
Cannot defer the call to Initialize() or similar delayed lifecycle methods.
Cannot refactor plugin creation logic as it's used by multiple services and needs to remain generic and eager.
Expected Behavior:
INotificationHandler should be triggered as expected even when IMediator.Publish() is called inside services initialized during plugin construction.
Actual Behavior:
The notification is silently dropped , no handler is triggered, though it is registered.
Beta Was this translation helpful? Give feedback.
All reactions