Inject notification service error

Very much a newbie here, so apologies in advance if this is obvious!

I have some of the other Radzen UI components working fine however, when I come to work with say the notification service, I seem to be getting an error with the @Inject line:

@page "/"
@using Radzen.Blazor

**@inject NotificationService notificationService**
    

<h1>Hello, world! from Blazor</h1>

Welcome to your new Blazor app.

<SurveyPrompt Title="How is Blazor working for you????" />

<RadzenButton Text=@($"Show success notification") Style="margin-bottom: 20px; width: 200px"
              Click="@(args => ShowNotification(new NotificationMessage() { Severity = "success", Summary = "Success Summary", Detail = "Success Detail", Duration = 4000 }))" />

@code {
    Dictionary<DateTime, string> events = new Dictionary<DateTime, string>();

    void ShowNotification(NotificationMessage message)
    {
        notificationService.Notify(message);

        events.Add(DateTime.Now, $"{message.Severity} notification");
        Invoke(() => { StateHasChanged(); });
    }
}

The error seems to suggest the service hasn't been added.. although I checked the github repo and checked for the startup.cs to see if there was the usual dependency injection "services.add" but couldn't see that?

I have to say, I am using .NET core 3 preview 7 with the latest Blazor templates and generated a "full stack" project, so perhaps I am a little too far ahead of the demos so far?

Many thanks in advance.

Hi @dsheardown,

You need to configure it in your Startup.cs file like this:

services.AddScoped<NotificationService>();

Here is how it is done in our demo application: https://github.com/akorchev/blazor.radzen.com/blob/master/Startup.cs#L34-L35

Excellent! thanks so much.

public static async Task Main(string[] args)

    {

        var builder = WebAssemblyHostBuilder.CreateDefault(args);

        builder.RootComponents.Add<App>("app");

builder.Services.AddScoped<NotificationService>();

        builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

        builder.Services.AddOidcAuthentication(options =>

        {

            // Configure your authentication provider options here.

            // For more information, see https://aka.ms/blazor-standalone-auth

            builder.Configuration.Bind("Local", options.ProviderOptions);

        });

        await builder.Build().RunAsync();

    }

hello, I got error whilel inject NotificationServicein in blazor wasm , the error message was : " Notificationservices" could not be found
I am using dotnet core Version="3.2.1 and Radzen 2.11.18
can you please take a look , if i did it wrong ?

!Okie, I found out I forgot to import Radzen by using radzen ;