Home > OS >  SendGrid client lifetime and thread-safety
SendGrid client lifetime and thread-safety

Time:11-17

From GitHub I see that normal way to register the SendGrid client is using transient lifetime. I am not able to find info about thread safety for SendGrid client. Is it possible to use it in multiple threads? Any pros/cons to register it as a transient dependency, not as a singleton?

CodePudding user response:

The SendGrid client is registered as a transient service when calling the AddSendGrid method. If you'd like to register the service as scoped or singleton you can, but there's no built-in helper. You can copy the source code for AddSendGrid and adjust as needed.

The SendGrid client and its dependencies (HTTP client) do not have code that could cause race conditions or deadlocks as far as I can tell, so it should be thread safe.

  • Related