twilio-csharp icon indicating copy to clipboard operation
twilio-csharp copied to clipboard

TwilioClient for multi-tenancy apps

Open MikeAlhayek opened this issue 1 year ago • 2 comments

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.

MikeAlhayek avatar Aug 25 '23 18:08 MikeAlhayek

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

Swimburger avatar Sep 11 '23 13:09 Swimburger

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.

jassent avatar Jan 03 '24 18:01 jassent

Closing this issue as resolved by above comments

tiwarishubham635 avatar May 21 '24 18:05 tiwarishubham635