you will need to add the service in both projects. The server project will need the service for server interactive or client static pre-render. The client project when used as WASM will also need the service.
Blazor .Net 9 Default template simple usage of a service - porting from an earlier version
I tried to port this simple project:
https://github.com/JWealthall/BlazorWindowResize
to .net 9.0
So, I created a simple sample at:
https://github.com/KKacer/BlazorTestWindowSize
I'm trying to understand the usage and changes I need to do in the 2 Program.cs files (one in the Client project, and the other in the Server project)
What I did was placing all the Interfaces, Services and Models inside the Client project.
But using the same Program.cs which was implemented in that project may not work here:
using BlazorWindowResize;
using BlazorWindowResize.Interfaces;
using BlazorWindowResize.Services;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped<IBrowserService, BrowserService>();
var host = builder.Build();
await host.Services.GetRequiredService<IBrowserService>().Init();
await host.RunAsync();
Should I add part of these implementations in the Server project? What changes are needed and why?
Thanks in advance for any help.
1 additional answer
Sort by: Most helpful
-
Kasrak 46 Reputation points
2025-01-17T09:08:26.5+00:00 Thanks for the hint,
with some edits, I was able to figure it out.