Reuse HttpClient instance
danports opened this issue · 4 comments
The library instantiates a new HttpClient
instance for every API call:
Plaid.NET/src/Plaid/PlaidClient.cs
Line 310 in 1acbd93
This runs contrary to Microsoft's guidance, and I can personally attest to the fact that ignoring this guidance does lead to problems in production (not with this library specifically, but with others I used heavily). At the very least, the HttpClient
instance should be cached for the lifetime of the PlaidClient
instance, if not made static
.
@danports Technically, this advice is only accurate for WPF or Console applications. For long-running applications, better advice from Microsoft is given here. You can see how this is implemented in my fork here:
https://github.com/viceroypenguin/Going.Plaid.NET/blob/97b9027c4acd90c38b4ffda09a5ef1777e083a70/src/Plaid/PlaidClient.cs#L291
@viceroypenguin would you like access to make commits?
@Ackara - the main reason I forked was due to the poor release timing. commit access does not address this concern. If you would like to give me commit access and ask me to push commits from my fork into your repo, that would be fine. However, my primary focus (vis a vis Plaid) will be on my repo, with active releases under the nuget package I've created. If you wish to remain active, feel free to do so; on the other hand, if you decide you don't want to be active, feel free to send people my way.
I implemented the client using IHttpClientFactory pattern. This should solve your issue