Repository navigation
Conversation
ApiClient always created its own private HttpClient, so handlers registered via IHttpClientFactory (e.g. Microsoft.Extensions.Http.Resilience) never applied to Xero API calls. - ApiClient: add ApiClient(HttpClient) and ApiClient(HttpClient, basePath). The injected client is caller-owned and not disposed by the SDK. - Api classes: add XxxApi(HttpClient, Configuration = null), defaulting to each API's base path. A single HttpClient constructor keeps the classes usable as typed clients via services.AddHttpClient<XxxApi>(). - Tests for routing, base paths, disposal ownership and typed-client DI. The Api classes are generated; the matching template change is still needed so the next spec release doesn't drop these constructors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 14, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #682
What
ApiClient: newApiClient(HttpClient)andApiClient(HttpClient, string basePath)constructors. The injected client is owned by the caller and is not disposed by the SDK.RequestOptions.Cookiesis not supported in this mode; the existing guard inExecthrows a clear error.XxxApi(HttpClient httpClient, Configuration configuration = null)constructor. Without a configuration, each class keeps its own default base path.HttpClientInjectionTests. The test project now referencesMicrosoft.Extensions.Http8.0.1 for the dependency-injection test.Why
ApiClientalways created its own privateHttpClient, and nothing let callers pass one in. So handlers registered throughIHttpClientFactorynever applied to Xero API calls, e.g.Microsoft.Extensions.Http.Resilience(AddStandardResilienceHandler), logging or telemetry. The only workaround was setting the private_httpClientfield by reflection.XeroClientin OAuth2Client already accepts anHttpClient; this gives the API calls the same option.Notes for reviewers
HttpClient, with an optionalConfiguration, rather than two overloads.ActivatorUtilities, which typed clients use, throws when more than one constructor accepts the given argument types. A test covers registering the class withAddHttpClient<AccountingApi>().api.mustache,ApiClient.mustache), or the next spec release will remove these constructors.ApiClient.Execbuilds a token that includesConfiguration.Timeoutbut passes the originalcancellationTokentoSendAsync, so the timeout is never applied.Testing
Test.Api.Client).AccountingApiTests/PayrollAuApiTests/BankFeedsApiTestsfailed with "connection refused" because the local mock server wasn't running. None of those failures relate to this change.🤖 Generated with Claude Code