Reputation: 4908
I have a new Blazor project in .NET 8. I have set it to use auto (both server and webassembly) globally. However I have non of the things I am used to seeing in a pre-.NET 8 webassembly project.
I don't have a shared project (although that is not an issue) and I do not have any controllers in the server project (which is certainly an issue).
I also can not add HttpClient
injection.
How on earth do I call the server project and how does it all work? Non of the tutorials seem to explain the very basics of how to communicate with the server from the webassembly project (obviously this used to simply be done using http calls to the controllers). Even the example code in the template fails to actually call anything on the server (the weather page used to do this in previous versions but now it simply populates the code in the page itself with a hard coded array).
Does anyone know of a good tutorial that explains this?
Upvotes: 0
Views: 659
Reputation: 14573
This will be required in both the server and client. Also just right click a empty Controllers
folder and add scaffolded item...
builder.Services.AddScoped(sp =>
{
NavigationManager navigation = sp.GetRequiredService<NavigationManager>();
return new HttpClient { BaseAddress = new Uri(navigation.BaseUri) };
});
Program.cs
...
builder.Services.AddControllers();
...
app.MapControllers();
Upvotes: 0