Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AddHttpClient in .NET 6 Worker Service

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

like image 729
Assis Zang Avatar asked Nov 28 '25 06:11

Assis Zang


1 Answers

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.

like image 113
Guru Stron Avatar answered Nov 29 '25 19:11

Guru Stron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!