C#C
C#3y ago
Very Funny

HttpClient is not being registered

c#
builder.Services
    .AddHttpClient<AdminService>(client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
    .AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

builder.Services.AddScoped<IAdminService, AdminService>();
I can confirm that the client.BaseAddress is correct.

c#
public class AdminService : IAdminService
{
    private readonly HttpClient _httpClient;

    public AdminService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }
...
}
For some reason the HttpClient is not getting registered in my AdminService. The base address is coming up null.

I do have the IAdminService scoped to both my client and server side apps. Not sure if that would be a problem (I am doing this, since when I wasn't my app just wouldn't work)

c#
// Client
builder.Services.AddScoped<IAdminService, AdminService>();

// Server
builder.Services.AddScoped<BlazorApp9.Client.APIs.IAdminService, AdminService>();
image.png
Was this page helpful?