0

Background: I need to write a REST api wrapper for a 3rd party client dll. However, they're saying that the dlls are not thread safe and we should make sure that our REST api only process one request at a time.

Question: How should we do it? It's my first time dealing with this kind of scenario so I'm currently exploring how possible this is.

kempyyyy
  • 224
  • 1
  • 3
  • 13

1 Answers1

-1

You can allow a single request at API using the locking mechanisms. Here is the code snippet:

public class Test 
{
  private static readonly object _lockObject = new object();
  [HttpGet]
  public IActionResult MethodName
  {
       lock (_lockObject)
        {
          //TODO: your code here.
        }
  }
 }
Rafaqat Ali
  • 676
  • 7
  • 26
  • I have tested this stuff, and it's working. you may further elaborate on your issue in detail so that I may help you. – Rafaqat Ali Dec 07 '19 at 21:25