Share via

HttpClientFactory

Dondon510 261 Reputation points
2022-08-08T07:11:56.353+00:00

I'm learning HttpClientFactory in my ASP MVC Net 6 simple project by following an article from https://code-maze.com/using-httpclientfactory-in-asp-net-core-applications/amp/ but it doesn't firing

in program.cs

builder.Services.AddHttpClient();
builder.Services.AddScoped<IHttpClientServiceImplementation, HttpClientFactoryService>();

public class HttpClientFactoryService : IHttpClientServiceImplementation
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly JsonSerializerOptions _options;

    public HttpClientFactoryService(IHttpClientFactory httpClientFactory)  
    {  
        _httpClientFactory = httpClientFactory;  

        _options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };  
    }  

    public async Task Execute()  
    {  
       ... some processes // I expect to do some process in here, but it doesn't fire  
    }  

}

public interface IHttpClientServiceImplementation
{
Task Execute();
}

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments

1 answer

Sort by: Most helpful
  1. AgaveJoe 31,341 Reputation points
    2022-08-08T12:21:24.287+00:00

    You did not share the implementation or where the Execute() method is called. Perhaps this is part of the previous tutorials? Anyway, the client code is that calls Execute() is here...

    https://github.com/CodeMazeBlog/httpclient-aspnetcore/blob/httpclientfactory-aspnetcore/CompanyEmployees.Client/CompanyEmployees.Client/Program.cs

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.