Closed
Description
Description
Hi
I'm sure this is an ID10T user issue!
I am trying to follow https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-8.0&pivots=webassemblyn and cannot register an HttpClient Service. Minimum steps :
- Create a new Project
- Select "Blazor Web App" template
- Choose Interactive render mode : WebAssembly
- Add to Client.Program.cs
builder.Services.AddScoped(sp =>
new HttpClient
{
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
}); - Add to Counter.razor
@using System.Net.Http
@Inject HttpClient Http - run project and navigate to Counter page
Error
An unhandled exception occurred while processing the request.
InvalidOperationException: Cannot provide a value for property 'Http' on type 'HttpClientIssue.Client.Pages.Counter'. There is no registered service of type 'System.Net.Http.HttpClient'.
[Enter feedback here]
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-8.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/call-web-api.md
Document ID
c7e59a08-1c60-32c2-75fd-33cb77ff7a5d
Article author
Metadata
Metadata
Assignees
Type
Projects
Status
Done