twilio-labs / twilio-aspnet

Integrate Twilio Programmable Messaging and Voice with ASP.NET Respond to webhooks with TwiML in seconds
Apache License 2.0
59 stars 30 forks source link

Support reloadOnChange and add better validation #116

Closed Swimburger closed 1 year ago

Swimburger commented 1 year ago

Previously, TwilioClientOptions and TwilioRequestValidationOptions would be configured during startup and would not automatically change when the .NET configuration is changed. With these changes, these options will update when configuration from configuration sources with reloadOnChange enabled are changed.

Additionally, the options are now validated using the built-in validation APIs.

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

Swimburger commented 1 year ago

Thank you @IEvangelist for the guidance and support!

Swimburger commented 1 year ago

I added the recommended overload following options guidance for library authors: https://learn.microsoft.com/en-us/dotnet/core/extensions/options-library-authors Closes #117

Swimburger commented 1 year ago

To limit the amount of permutations of overloads, I decided to remove the provideHttpClient parameter. I added it originally to make sure it could be provided by the user to override our default implementation using the HTTP client factory, but in hindsight, there's not really a benefit and nobody asked for it.

Users can still customize the HTTP client by overriding the "Twilio" named HTTP client like this:

builder.Services.AddTwilioClient();
builder.Services.AddHttpClient("Twilio")
    .ConfigureHttpClient(client =>
    {
        client.BaseAddress = new Uri("YOUR_PROXY_ADDRESS");
    })
    .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
    {
        // same options as the Twilio C# SDK
        AllowAutoRedirect = false
    });