refactor!: generated clients inherit ConnectorClientBase (#88)#90
refactor!: generated clients inherit ConnectorClientBase (#88)#90
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the generated connector clients to inherit from ConnectorClientBase (instead of implementing IDisposable and duplicating HTTP/auth/retry/JSON logic per connector), and aligns namespaces/exceptions/tests/docs with the new shared SDK infrastructure.
Changes:
- Introduces shared SDK infrastructure (
ConnectorClientBase,ConnectorException,TokenCredentialTokenProvider) and migrates generated clients to use it. - Regenerates 11 connector extension files to inherit the base class, switch namespaces to
Microsoft.Azure.Connectors.Sdk.*, and unify exceptions toConnectorException. - Updates unit tests and docs to reference the new namespaces and exception type.
Reviewed changes
Copilot reviewed 20 out of 33 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Azure.Connectors.Sdk.Tests/TriggerCallbackPayloadTests.cs | Updates Office365 namespace import to Microsoft.Azure.Connectors.Sdk.Office365. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/TeamsClientTests.cs | Updates Teams namespace + asserts unified ConnectorException. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/SmtpClientTests.cs | Updates Smtp namespace + renames/asserts unified ConnectorException. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/SharepointonlineClientTests.cs | Updates SharePointOnline namespace + unified exception assertions/construction. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/OnedriveforbusinessClientTests.cs | Updates OneDrive for Business namespace + unified exception assertions/construction. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/Office365usersClientTests.cs | Updates Office365Users namespace + unified exception assertions. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/Office365TriggerPayloadTests.cs | Updates Office365 namespace import. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/Office365ClientTests.cs | Updates Office365 namespace + unified exception assertions. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/MsgraphgroupsanduserClientTests.cs | Updates MsGraphGroupsAndUser namespace + unified exception assertions. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/MqClientTests.cs | Updates MQ namespace + renames/asserts unified ConnectorException. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/KustoClientTests.cs | Updates Kusto namespace + unified exception assertions/construction. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/DynamicSchemaTests.cs | Updates Teams namespace import. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/ConnectorConstantsTests.cs | Updates constants test to use SdkConnectors and new namespaces. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/AzureloganalyticsClientTests.cs | Updates Azure Log Analytics namespace + unified exception assertions/construction. |
| tests/Microsoft.Azure.Connectors.Sdk.Tests/AzureblobClientTests.cs | Updates Azure Blob namespace + unified exception assertions/construction. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/TeamsExtensions.cs | Migrates Teams client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/SmtpExtensions.cs | Migrates Smtp client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/SharepointonlineExtensions.cs | Migrates SharePointOnline client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/OnedriveforbusinessExtensions.cs | Migrates OneDrive for Business client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/Office365usersExtensions.cs | Migrates Office365Users client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/Office365Extensions.cs | Migrates Office365 client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/MsgraphgroupsanduserExtensions.cs | Migrates MsGraphGroupsAndUser client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/MqExtensions.cs | Migrates MQ client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/KustoExtensions.cs | Migrates Kusto client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/AzureloganalyticsExtensions.cs | Migrates Azure Log Analytics client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/AzureblobExtensions.cs | Migrates Azure Blob client to ConnectorClientBase, new namespace, unified exception. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/ManagedConnectors.cs | Renames registry type to SdkConnectors and updates usage comments/namespaces. |
| src/Microsoft.Azure.Connectors.Sdk/Generated/ConnectorNames.cs | Updates header text (and minor doc text) to match new SDK branding. |
| src/Microsoft.Azure.Connectors.Sdk/ConnectorException.cs | Adds unified exception type with connector/operation/status/body. |
| src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs | Adds shared constructors + CallConnectorAsync + SSRF-protected URL resolution. |
| src/Microsoft.Azure.Connectors.Sdk/Authentication/TokenCredentialTokenProvider.cs | Adds adapter from Azure.Core.TokenCredential to ITokenProvider. |
| README.md | Updates docs to describe new base/exceptions/options and adds a configuration sample. |
| CHANGELOG.md | Documents breaking changes and new shared types in Unreleased. |
Breaking change: generated connector clients now inherit from
ConnectorClientBase instead of implementing IDisposable directly.
SDK core changes:
- ConnectorClientBase: add convenience constructors (connectionRuntimeUrl
+ TokenCredential), CallConnectorAsync, ResolveUrl with SSRF protection,
shared ApiHubScopes and JsonOptions
- TokenCredentialTokenProvider: adapts Azure.Core.TokenCredential to
ITokenProvider
- ConnectorException: unified exception with ConnectorName, Operation,
StatusCode, ResponseBody (replaces per-connector exception types)
Generated files (regenerated via updated CodefulSdkGenerator):
- All 11 clients inherit ConnectorClientBase, override ConnectorName
- Accept optional ConnectorClientOptions for retry/timeout
- Namespace changed: DirectClient.{Connector} -> Sdk.{Connector}
- DirectClientConnectors -> SdkConnectors
Tests updated for ConnectorException, new namespaces, SdkConnectors.
Closes #88
- Remove unused System.Net.Http.Headers using from ConnectorClientBase - Add guard in ResolveUrl for empty _connectionRuntimeUrl - Fix README Quick Start namespace to Sdk.Office365 - Add Operation to ConnectorException description in README - Fix formatting in 5 test files (constructor arg wrapping)
- Make managedIdentityClientId parameter nullable (string?) - Guard ResolveUrl against empty _connectionRuntimeUrl for relative paths - ApplyBaseUri: only set BaseUri when caller did not provide one - Add 'using System;' to README Quick Start snippet - Update DirectClient namespace references in GENERATION.md, Generated/README.md, and trigger-registration SKILL.md - Regenerated all 11 connectors via updated CodefulSdkGenerator
Use Uri.TryCreate with UriKind.Absolute and throw ArgumentException with actionable message instead of letting UriFormatException propagate.
Generated files use #nullable disable so string? triggers CS8632. Regenerated all 11 connectors with string parameter that forwards to the nullable-enabled base class.
d296a8e to
f4fd5e4
Compare
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<string> GetAccessTokenAsync(string[] scopes, CancellationToken cancellationToken = default) |
There was a problem hiding this comment.
General suggestion: I recommend always having CancellationToken cancellationToken be a required parameter with very few exceptional circumstances. Allowing it to be unused by the caller can introduce unexpected hangs, soft-locks, and degraded performance.
This suggestion is speaking with my own .NET experience and preferences, and it is not aligned with the Azure SDK .NET guidelines.
There was a problem hiding this comment.
I paid the significant cost of updating thousands of lines of the Azure MCP server code to plumb through CancellationToken parameters during our drive to release a remote HTTP mode.
It took me
a lot
of time
| { | ||
| ArgumentNullException.ThrowIfNull(scopes); | ||
|
|
||
| if (scopes.Length == 0) |
There was a problem hiding this comment.
Nit: checking the length, but not the contents of the array. Do we care about null or empty string array elements?
| var context = new TokenRequestContext(scopes); | ||
| var token = await this._credential | ||
| .GetTokenAsync(context, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); |
There was a problem hiding this comment.
Why include ConfigureAwait(false)?
Summary
Generated connector clients now inherit from
ConnectorClientBaseinstead of implementingIDisposabledirectly. This eliminates ~1,500 lines of duplicated boilerplate across 11 connector files.Breaking changes
ConnectorClientOptionsparameter (position 3),HttpClientmoves to position 4Office365ConnectorException) replaced by unifiedConnectorExceptionMicrosoft.Azure.Connectors.DirectClient.{Connector}→Microsoft.Azure.Connectors.Sdk.{Connector}DirectClientConnectors→SdkConnectorsSDK core changes
ConnectorClientBaseCallConnectorAsync,ResolveUrl(SSRF), shared JSON optionsTokenCredentialTokenProviderAzure.Core.TokenCredentialtoITokenProviderConnectorExceptionConnectorName,Operation,StatusCode,ResponseBodyGenerated files
All 11 connector files regenerated via updated
CodefulSdkGenerator(not hand-edited). Each client now inheritsConnectorClientBase, overridesConnectorName, and accepts optionalConnectorClientOptions.Related PRs
Test results
218/218 tests pass ✅
Closes #88