I have developed a restful WEB API 2 (C#, .NET 4.7) for an internal integration project. In my API's backend, I need to use a vendor's dll in order to process the provided input.
The vendor's dll is written in C, and it has a limitation that, there cannot be more than 8 initialized instances at the same time.
Since my REST API can be called multiple times concurrently, there is a risk that I may hit the 8 instances limit during a busy time. (My API is not public. There is a little chance that this can happen. But still, I need to stay safe.)
To prevent this, I was planning to keep the current count of the running instances on a thread-safe singleton variable. And if I can maintain the increment/decrement logic where I initialize the C dll, I can stay safe.
Since a REST API is stateless, is it a good practice to use a static thread-safe approach to implement this? Or there could be better approaches like using server cache, Application State ( Application["VariableName"] = "Value" ), or even a flat file.
And I need to add that, a database is not an option at my situation.