Sending MediatR INotifications to the client over SignalR
See original GitHub issueFor every INotification
you want to send to the client over SignalR, you have to create an INotificationHandler
for that specific notification, which then calls the hubcontext to send a specific INotificationMessage
(another object alltogether) to the connected clients.
In my app I’m building, I have already quite some notifications like that, and was thinking we could make this probably generic in a way you don’t have to create separate INotificationHandler
s and INotificationMessage
s for all the INotification
s you want to be sent to the client as well.
In my research around this, I found this article which is looking very close to what we need: https://remibou.github.io/Realtime-update-with-Blazor-WASM-SignalR-and-MediatR/ There’s an issue there though pointed out in the comments… and another pointer to an interesting library in this regard: https://github.com/KuraiAndras/MediatR.Courier
I think combining those 2 should be able to give a a nice implementation of something like this…
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (9 by maintainers)
Top GitHub Comments
Oh, an about the
INotificationMessage
: I’ve updated that interface to just be a marker interface. There were 2 properties in there:One was
string MessageType
, which in every implementation returned the valuenameof(SpecificNotificationMessage)
. Which was then only used inINotificationService
, to us asmethodName
parameter in theHubContext.SendAsync
calls. There, I simply replacednotification.MessageType
withnotification.GetType().Name
in every call tohubContext.SendAsync
, which does exactly the same thing (without having to implement aMessageType
string on everyINotificationMessage
…The other one was just
string Message
which wasn’t actually needed in everyINotificationMessage
so no need to be on the Interface. One can easily implement it if it’s actually needed for a specificINotificationMessage
.Maybe this should be in another issue… but I can create a separate PR for this if you want… just let me know!
So something like this should work?