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:
Obviously the service needs to be entirely on the client, so the component which consumes it has:
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?
12 Replies
possibly pre-rendering
Shouldn't that have been prevented by the render mode?
no
all modes are still prerendered
you can disable with something like
new InteractiveWebassembly(false)
false being prerenderWhere would that constructor be placed? I don't think I have anything like that.
where you define the mode currently
are you trying to use that clientside component in a server component ?
@rendermode @(new InteractiveWebassembly(prerender: false))
Got it, thanks.
The Sheet component is on a page in the Client project.
Do I need a @using for that? Blazor components break intellisense...
don't believe so
Ah, got it.
ah
was just gonna go to the docs
side note you can read up here https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0#prerendering
🤞
Alright, thanks.
I got rid of the error, now I need to figure out why nothing is displaying.