I am trying to use HttpClient in my .net core 2.0 project and for that I have injected HttpClient in my controller. But when I am trying to configure httpclient in my startup.cs I am getting this error: "IServiceCollection does not contain a defintion for AddHttpClient". I have already referenced using Microsoft.AspNetCore.Http;
and using Microsoft.Extensions.DependencyInjection;
and here is what I am trying to do:
services.AddHttpClient<TestController>();
It's working fine in other project with same namespaces but here I am getting the error. Any help?
AddHttpClient(IServiceCollection, String)Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.
AddScoped(IServiceCollection, Type, Type) Adds a scoped service of the type specified in serviceType with an implementation of the type specified in implementationType to the specified IServiceCollection.
ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<IServiceProvider,HttpMessageHandler>) Adds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.
You need to install Microsoft.Extensions.Http
from NuGet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With