Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IServiceCollection does not contain a defintion for AddHttpClient

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?

like image 497
Ask Avatar asked Aug 30 '18 07:08

Ask


People also ask

What is AddHttpClient?

AddHttpClient(IServiceCollection, String)Adds the IHttpClientFactory and related services to the IServiceCollection and configures a named HttpClient.

What is IServiceCollection in .NET core?

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.

What is ConfigurePrimaryHttpMessageHandler?

ConfigurePrimaryHttpMessageHandler(IHttpClientBuilder, Func<IServiceProvider,HttpMessageHandler>) Adds a delegate that will be used to configure the primary HttpMessageHandler for a named HttpClient.


1 Answers

You need to install Microsoft.Extensions.Http from NuGet

like image 147
Rahul Jain Avatar answered Sep 19 '22 21:09

Rahul Jain