Blazor Global Events
ฝัง
- เผยแพร่เมื่อ 23 ก.ย. 2024
- in this Video I show you how we can create a base class. All the types (Razor Componnents, Classed etc) that inherit this type can then subscribe to its events and also raise those. Creator: David Eggenberger Code: github.com/Dav...
Do not use Inheritance! You can define an Interface instead and register it as Singleton and Inject it
is there a way to do this without the copying and pasting?
How would you do it for components that already inherit something else ?
Ah got it, you can just add the static events to a Class and inject it.
can I use this approach to send notifications globally on the application, but also to all users using the application? or that will need some signalr hub? I want like a notification system, that shows up on all users using the application
you need SignalR for that
Can I use as a global notification like Toasters which shows the error, warning, success messages ?
Currently I am using TelerikNotification.
yes you can! You can for example subsrcibe to the wanted event from the MainLayout to then show you Toast message
Hey! Great stuff about Events!
I get an error I can't quite figure out. Will you help me?
Unhandled exception rendering component: The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.
It happens at:
UpdateTriggered += (o, args) => ...
(Using Blazor Server)
SOLVED:
Changed _Host.cshtml from "ServerPrerendered" to "Server"
Nice
Reset, not Resseted.