Open Kjelli opened 4 months ago
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
bump
I seem to have the same problem in my project
I stumpled upon this issue as well but solved it by copying the definition of the handler from https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/blob/020d8817ae84e18d61bbf343b00558249c37f899/src/TestApp/ConstrainedPingedHandler.cs#L8
I stumpled upon this issue as well but solved it by copying the definition of the handler from https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/blob/020d8817ae84e18d61bbf343b00558249c37f899/src/TestApp/ConstrainedPingedHandler.cs#L8
It does not solve case C.
It's been over a year since I last wrestled with notifications. I threw in the towel and pursued an alternative approach described with pseudo code in this thread last year. Drastically simplified notifications and cloud events and made execution order and debugging possible. Unfortunately, it seems the saga continues and I no longer have access to the code base. In case it helps anyone, the suggested alternative at the bottom of this thread worked like a charm...
The issue at hand
When using interfaced notifications, and handlers for the interfaces - the handler does not run unless there exists a handler targetting a concrete implementation of the respective interface.
Steps to reproduce:
Bootstrap
A) A simple notification handler that runs
B) An interfaced notification handler that runs
C) Now for the interfaced notification handler that does not run
Cases A and B are as expected, whereas case C is strange - I would expect
InterfacedGreeterHandler
to be run.Further notes
I am not sure any of this is relevant, but I did some investigating.
I have a theory that this issue is caused near
NotificationHandlerWrapper
. Inspecting the service collection, I verify that it correctly containsINotificationHandler<IGreeterInterface>
, but it does not containINotificationHandler<ImplementingGreeterNotification>
.From these lines I see that
IServiceProvider.GetServices<INotificationHandler<ImplementingGreeterNotification>>
does not return anything, which I suspect subsequently fails to resolve a respectiveNotificationHandlerExecutor
. https://github.com/jbogard/MediatR/blob/cac76bee59a0f61c99554d76d4c39d67810fb406/src/MediatR/Wrappers/NotificationHandlerWrapper.cs#L24-L26It does make sense I suppose, but at face value this looks like odd behavior either way.
I tested a more basic, yet potentially related case; implementing a catch-all
INotificationHandler<INotification>
never runs if there are no otherINotificationHandler
-types registered.