Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDFcoHttpClient

The correct way to use HttpClient in .NET applications

Install via NuGet

To install PDFcoHttpClient, run the following command in the Package Manager Console:

PM> Install-Package PDFcoHttpClient

You can also view the package page on NuGet.

Usage:

Once you've got the HttpClientFactory defined, up next is registering the factory with your IoC container of choice.

 ioc.For<IHttpClientFactory>() 
      .Singleton() 
      .Add<HttpClientFactory>();

Then declare your dependency using constructor injection and use the HttpClientFactory.

namespace Web.Controllers
{
    public class CustomerController : Controller
    {
        private readonly IHttpClientFactory _httpClientFactory;
        public CustomerController(IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
        }

        public async Task<IActionResult> GetById(int id)
        {
            var httpClient = _httpClientFactory.GetOrCreate(new Uri("http://pdfco.ir/customers"));
            var response = await httpClient.GetAsync(...);
            ... 
        }

About

The correct way to use HttpClient in .NET applications

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages