.NET 8 addhttpclient funktioniert nicht wie erwartetC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 .NET 8 addhttpclient funktioniert nicht wie erwartet

Post by Anonymous »

Ich registriere meinen httpclient so: < /p>

Code: Select all

builder.Services.AddHttpClient(i =>
{
i.BaseAddress = new Uri("https://google.com"); //breakpoint here never stops
});
und MyClass 's Konstruktor wird wie
implementiert

Code: Select all

public MyClass(HttpClient client)
{
// client.BaseAddress is null here
}
< /code>
Was mache ich falsch? Meine Erwartung hier ist der Client 
in der Betonklasse ist vorkonfiguriert ...
Ich habe bereits versucht, mich zu registrieren wie:
  • Code: Select all

    AddHttpClient("global", i => { i.BaseAddress = new Uri("https://google.com"); }
  • Code: Select all

    AddHttpClient(i => { i.BaseAddress = new Uri("https://google.com"); }
  • AddHttpClient(i => { i.BaseAddress = new Uri("https://google.com"); } ​​

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post