Description
In some 0.13.x
update, the BunqContext
class was introduced, implementing the Singleton pattern on the ApiContext
.
Every API call goes in some way like this:
var apiClient = new ApiClient(GetApiContext()); // GetApiContext() - fetches the Singleton instance
var response = apiClient.Get(...);
The potential issue (and the one I got now in my web project) is in multi-threaded and multi-user code where I need to make API calls with different ApiContext
instances, i.e. different API keys.
One scenario is: user A loads the context, then user B loads his context, then user A makes a call with the context loaded from B (because it's a global static variable inside the SDK).
The workaround would be to lock my methods with a static
objects, but then I have to do it for every method with the same Bunq API call and spaghetti code arises.
Why did you introduce the singleton ApiContext
and left the earlier approach? How can I easily and in 'a more dev-friendly way' solve this issue?