Eptagone / Vite.AspNetCore

Small library to integrate Vite into ASP.NET projects
MIT License
243 stars 34 forks source link

Improve HttpClient Usage in Middleware #34

Closed orialmog closed 1 year ago

orialmog commented 1 year ago

This commit addresses the usage of HttpClient within the middleware. Previously, a new HttpClient was instantiated with each request, which, while functional, could lead to potential issues under high load.

This update leverages ASP.NET Core's built-in IHttpClientFactory for managing HttpClient instances. This factory helps in efficiently managing HttpClient lifecycles, reducing the risk of socket exhaustion, and increasing the overall performance.

Changes include:

  1. Injecting IHttpClientFactory in the middleware's constructor.
  2. Utilizing the factory to create HttpClient instances within the ProxyAsync method.

These modifications ensure a more optimal use of resources and promote better application stability and scalability.