Home > Enterprise >  How to using AddHttpClient in .NET 6 Worker Service
How to using AddHttpClient in .NET 6 Worker Service

Time:06-05

Is there an alternative way to add the "AddHttpClient()" setting in the .NET 6 Worker Service template?

In Minimal APIs for example we have available:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpClient();

In the Worker Service template is not:

enter image description here

CodePudding user response:

Install matching version of Microsoft.Extensions.Http nuget (for .NET 6 6.0.0 should be fine) and HttpClientFactoryServiceCollectionExtensions.AddHttpClient will become available for your project.

CodePudding user response:

Just add HttpClient like you add every service by AddScoped<IHttpClient, HttpClient>()

  • Related