C#C
C#14mo ago
Grault

Blazor WASM: Injecting a service

I'm trying to inject a service to extract details (dimensions, so far) of the browser. The code for the service is from https://blazor.tips/blazor-how-to-ready-window-dimensions/ .

The service is registered in the Client project's Program.cs:
C#
builder.Services.AddScoped<BrowserService>();

Obviously the service needs to be entirely on the client, so the component which consumes it has:
C#
@rendermode InteractiveWebAssembly
@inject BrowserService Browser

When I run the project and open the page which contains the component, I receive:
>InvalidOperationException: Cannot provide a value for property 'Browser' on type 'Quilt.Client.Components.Sheet'. There is no registered service of type 'Quilt.Client.Utilities.BrowserService'.

Is some of the component running on the server? Why?
Was this page helpful?