Closed GerardSmit closed 1 year ago
Now that I think about it. The config is being stored in the end-points:
So changing the static configuration will not doing anything. It's not as critical than I thought but it can still happen when the MoneybirdClient instance is being constructed 🤔
This PR fixes two issues:
1. The configuration is being stored static
Currently all instances of MoneybirdClient share the same configuration. This can cause a race condition if there are multiple threads that creates their own MoneybirdClient with different configurations.
For example:
In this case the
firstMoneybirdClient
will get the configuration of thesecondMoneybirdClient
and sends the request with the wrong credentials.This has been fixed by giving each MoneybirdClient their own configuration instance, instead of being static.
2. It's not possible to pass the HttpClient
The MoneybirdClient always creates their own HttpClient. When you're using IHttpClientFactory, it's not possible to pass the HttpClient that the client should use. I've made the constructor public and added the HttpClient as argument.
I've also implemented IDisposable to dispose the HttpClient.
Example:
Note: MoneybirdClient.GetInstance does not dispose the HttpClient since it's possible that a different thread is still using the HttpClient, causing all the requests to abort.