[Solved] RadzenNotification and NotificationService problem

Hello everyone.

I'm turning to you today to ask for help about RadzenNotifications in Blazor Server. I have a problem that I have tried to turn in all directions but I can't solve it.

Let me set the context here:

I have a BackgroundTask (.cs) that takes care of checking the connection with an external device and send alarms if needed (for exemple a connection lost). This one works correctly because the program manages well to send and receive e-mails about it and store it on the DB. This task uses a custom Service "MsaNotificationService" (.cs) to do this.

After that, I would like to use RadzenNotification to display this alarm directly on the web application screen (this is where I'm stuck). I have tried several methods but I will already present you the following one:

First of all, as the doc says, I added my services in Startup.cs :

I then added in MainLayout.razor as the doc says too.

So in background task i create my "MsaNotificationService" and when an problem is detected I call his method "SendEvent" that Notify an Action with the NotificationMessage :

The relatives event/methods :
image

Then, In my MainLayout.razor that inherits MainLayoutBase, i added this block of code to fire the previous event and use the NotificationService (I tried to do it directly in the MainLayoutBase too):

Unfortunatly when I invoke my OnAction on MsaNotificationService, the event is never fired... Does anyone know why ?

A second approach I used what to use "NotificationService" directly in "MsaNotificationService" by Dependency Injection and call the NotificationService.Notify(message) directly from my SendEvent() method :

image

I Used this CreateScope() method because i had ambiguous contructor errors if I used DI by parameters.

But this method has no effect, no pop-ups notification feedback are coming up.

As you can see, I am stuck on this problem. I have also tried other methods but without success. Do you have any idea how I could get that succed ?

Thank you very much in advance !

1 Like

I think you need to solve this one first. This is the right approach to invoke the notification service. It may also need you to call InvokeAsync(StateHasChanged) as OnAction is likely invoked outside of the Blazor lifecycle.

Hello @korchev, Thank you for your answer !

Finally I got this work. You were right, I went in too much direction and didn't tried to figure out why the event wasn't fired. Finally I wasn't referencing the good "MsaNotificationService". I had to create one as static and use only and only this one. When I was Injecting the MsaNotificationService, I was creating a new one that couldn't receive the events.

I Hope this post will help other persons in the future !

1 Like