© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
Very Funny

HttpClient is not being registered

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

builder.Services.AddScoped<IAdminService, AdminService>();
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.

public class AdminService : IAdminService
{
    private readonly HttpClient _httpClient;

    public AdminService(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }
...
}
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)

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

// Server
builder.Services.AddScoped<BlazorApp9.Client.APIs.IAdminService, AdminService>();
// Client
builder.Services.AddScoped<IAdminService, AdminService>();

// Server
builder.Services.AddScoped<BlazorApp9.Client.APIs.IAdminService, AdminService>();
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

AboutView not registered?
C#CC# / help
11mo ago
HttpClient.GetStringAsync() is slow
C#CC# / help
4y ago
HTTPClient
C#CC# / help
2y ago
HttpClient does not return anything
C#CC# / help
3y ago