我想使用新的HttpClientFactory
,但我无法设置它。
我有以下内容(我只是把点头的例子放在一起来解释我的观点)
public class MyGitHubClient
{
public MyGitHubClient(HttpClient client)
{
Client = client;
}
public HttpClient Client { get; }
}
然后在我的webapi.Startup
我有
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient<MyGitHubClient>(client =>
{
client.BaseAddress = new Uri("https://api.github.com/");
//etc..
});
//NOW I get error "Class name is not valid at this point" for "MyGitHubClient" below
services.AddSingleton<IThirdPartyService>(x => new ThirdPartyService(MyGitHubClient,someOtherParamHere));
///etc...
}
第三方构造器
public ThirdPartyService(HttpClient httpClient, string anotherParm)
{
}
HttpClientFactory
当我必须调用一个我无法控制的类时,我该如何使用?