C
C#13mo 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>();
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;
}
...
}
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>();
c#
// Client
builder.Services.AddScoped<IAdminService, AdminService>();

// Server
builder.Services.AddScoped<BlazorApp9.Client.APIs.IAdminService, AdminService>();
No description
3 Replies
Very Funny
Very FunnyOP13mo ago
The above debugging is from the AdminService on my clientside Sorted it, relied to heavily on impliclty defined variables. Even though I thought I had confirmed they were correcct i.e. builder.HostEnvironment.BaseAddress
Very Funny
Very FunnyOP13mo ago
Like it would register as correct
No description
Very Funny
Very FunnyOP13mo ago
But for some reason it decided it didn't want to persist to my AdminService Scratch that, shit still broken
Want results from more Discord servers?
Add your server