Skip to content

refactor!: generated clients inherit ConnectorClientBase (#88)#90

Merged
daviburg merged 6 commits intomainfrom
feature/client-options-inherit
May 5, 2026
Merged

refactor!: generated clients inherit ConnectorClientBase (#88)#90
daviburg merged 6 commits intomainfrom
feature/client-options-inherit

Conversation

@daviburg
Copy link
Copy Markdown
Member

@daviburg daviburg commented May 2, 2026

Summary

Generated connector clients now inherit from ConnectorClientBase instead of implementing IDisposable directly. This eliminates ~1,500 lines of duplicated boilerplate across 11 connector files.

Breaking changes

  • Constructor signature: new optional ConnectorClientOptions parameter (position 3), HttpClient moves to position 4
  • Exception types: per-connector exceptions (e.g., Office365ConnectorException) replaced by unified ConnectorException
  • Namespace: Microsoft.Azure.Connectors.DirectClient.{Connector}Microsoft.Azure.Connectors.Sdk.{Connector}
  • Navigator class: DirectClientConnectorsSdkConnectors

SDK core changes

New type Purpose
ConnectorClientBase Convenience constructors, CallConnectorAsync, ResolveUrl (SSRF), shared JSON options
TokenCredentialTokenProvider Adapts Azure.Core.TokenCredential to ITokenProvider
ConnectorException Unified exception with ConnectorName, Operation, StatusCode, ResponseBody

Generated files

All 11 connector files regenerated via updated CodefulSdkGenerator (not hand-edited). Each client now inherits ConnectorClientBase, overrides ConnectorName, and accepts optional ConnectorClientOptions.

Related PRs

Test results

218/218 tests pass ✅

Closes #88

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to ConnectorException.
  • 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.

Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs Outdated
Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs
Comment thread src/Microsoft.Azure.Connectors.Sdk/Generated/SmtpExtensions.cs
Comment thread src/Microsoft.Azure.Connectors.Sdk/Generated/SmtpExtensions.cs
Comment thread README.md Outdated
Comment thread README.md Outdated
Copilot AI review requested due to automatic review settings May 2, 2026 04:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 33 changed files in this pull request and generated 4 comments.

Comment thread src/Microsoft.Azure.Connectors.Sdk/Generated/SmtpExtensions.cs
Comment thread src/Microsoft.Azure.Connectors.Sdk/Generated/ConnectorNames.cs
Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs
Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 33 changed files in this pull request and generated 5 comments.

Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs Outdated
Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs
Comment thread README.md
Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs
Comment thread README.md
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 36 changed files in this pull request and generated 1 comment.

Comment thread src/Microsoft.Azure.Connectors.Sdk/ConnectorClientBase.cs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 36 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 36 changed files in this pull request and generated no new comments.

@daviburg daviburg enabled auto-merge (squash) May 4, 2026 19:13
anuchandy
anuchandy previously approved these changes May 5, 2026
daviburg added 4 commits May 5, 2026 09:08
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
daviburg added 2 commits May 5, 2026 09:08
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.
@daviburg daviburg force-pushed the feature/client-options-inherit branch from d296a8e to f4fd5e4 Compare May 5, 2026 16:09
@daviburg daviburg disabled auto-merge May 5, 2026 16:22
@daviburg daviburg merged commit f315d17 into main May 5, 2026
10 checks passed
@daviburg daviburg deleted the feature/client-options-inherit branch May 5, 2026 16:22
Copy link
Copy Markdown
Member

@vukelich vukelich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor ideas

}

/// <inheritdoc />
public async Task<string> GetAccessTokenAsync(string[] scopes, CancellationToken cancellationToken = default)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why include ConfigureAwait(false)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConnectorClientOptions: inherit from Azure.Core.ClientOptions and remove custom retry properties

4 participants