twilio-csharp
twilio-csharp copied to clipboard
TwilioClient for multi-tenancy apps
Currently the C#
twilio SDK does not allow us to use it in a multi-tenancy app. The problem with the existing code, is that is stores the username, password and others is a static variable. When you use this SDK with an app that supports multi-tenancy, you may end up using invalid parameters for requests since it is not thread-safe. If your are using an interface for the client, we could have easily replaced your default implementation with once that would work in a multi-tenancy apps.
While the docs all use the static client, you can instantiate your own ITwilioRestClient
instances.
The Twilio.AspNet.Core library doesn't support multi-tenancy, but you can inspire on the source code and add support for it yourself: https://github.com/twilio-labs/twilio-aspnet/blob/main/src/Twilio.AspNet.Core/TwilioClientDependencyInjectionExtensions.cs
This thread on Stackoverflow titled "What Pattern to Use for TwilioRestClient with Dependency Injection" shows how to use TwilioClient in a multi-tenancy app. I can confirm it works and have 1 app that accesses multiple accounts with different AccountSid and AuthToken combinations and it interfaces with Polly v7 as well as Polly v8 for resilient httpclients.
Closing this issue as resolved by above comments