Can I use HttpClientFactory in a .NET.core app which is not ASP.NET Core?

According to the documentation HttpClientFactory is a part of .Net Core 2.1, so you don’t need ASP.NET to use it. And there some ways to use are described. The easiest way would be to use Microsoft.Extensions.DependencyInjection with AddHttpClient extension method.

static void Main(string[] args)
{
    var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider();

    var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();

    var client = httpClientFactory.CreateClient();
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)