I'm using a Blazor web assembly project with .NET 8 "Blazor Web App" project, which supports both client (only WASM) and server rendering (SSR pages for authorization) content.
I'm a bit confused by how IoC work. That's something that the doc does not mention, but clearly reproduced on brand new "Blazor Web App" project: for pages defined as @rendermode InteractiveWebAssembly (for example Counter.razor with injected services like @inject HttpClient), I have to define service HttpClient in 2 places: Program.cs of the client project, and Program.cs of the server project, even if it's only used inside wasm. If I miss one place, it throws exception that HttpClient service is not defined.
What probably happens it renders the InteractiveWebAssembly page on the server side first, and then all further interactions carrying via wasm. So WebAssembly in "Blazor Web App" seems to be treated differently from what it used to be in a regular WebAssembly project. I know there is another type of WebAssembly type of project, that supports wasm only, but I want to have server side at my disposal too. So I wonder if there is any way around it, if I want for some pages having wasm-only rendering, no server rendering at all?
Also I tried the option to be
@(new InteractiveWebAssemblyRenderMode(false))
It is working with WASM but SSR pages cannot work for authorization, any advice ?
I tried to change the render mode WASM was working, but SSR pages are not working
HttpClientfor? How you solve your issue is dependant on how you are using it? More generally this commentary of mine provides more detail on building a mixed mode site - github.com/ShaunCurtis/Blazor.ExploreRendering/blob/master/…