Skip to content

feat: Use SDK DI extension methods, migrate to Azure.Connectors.Sdk namespace#37

Closed
daviburg wants to merge 3 commits intomainfrom
feature/di-extensions
Closed

feat: Use SDK DI extension methods, migrate to Azure.Connectors.Sdk namespace#37
daviburg wants to merge 3 commits intomainfrom
feature/di-extensions

Conversation

@daviburg
Copy link
Copy Markdown
Member

@daviburg daviburg commented May 7, 2026

Summary

Replace ~130 lines of manual DI boilerplate in Program.cs with the new SDK extension methods from Azure/Connectors-NET-SDK#117.

Before (Program.cs — 164 lines)

services.AddOptions<ConnectorOptions>()
    .Bind(configuration.GetSection(ConnectorOptions.SectionName))
    .ValidateDataAnnotations()
    .ValidateOnStart();

services.AddSingleton<Office365Client>(serviceProvider =>
{
    var options = serviceProvider.GetRequiredService<IOptions<ConnectorOptions>>().Value;
    return options.Office365.ManagedIdentityClientId != null
        ? new Office365Client(options.Office365.ConnectionRuntimeUrl, ...)
        : new Office365Client(options.Office365.ConnectionRuntimeUrl);
});
// ... repeated 9 more times

After (Program.cs — 33 lines)

var connectors = hostContext.Configuration.GetSection("Connectors");

services
    .AddOffice365Client(connectors.GetSection("Office365"))
    .AddSharepointonlineClient(connectors.GetSection("SharePoint"))
    .AddTeamsClient(connectors.GetSection("Teams"))
    // ...

Changes

  • Program.cs: Replace 10 manual factory registrations with 9 one-liner extension calls
  • Remove Configuration/ConnectorOptions.cs — no longer needed (was 250 lines of per-connector options classes)
  • Remove AzureLogAnalyticsFunctions.cs — connector deprecated in SDK, replaced by azuremonitorlogs
  • Namespace migration: Microsoft.Azure.Connectors.DirectClient.* to Azure.Connectors.Sdk.*
  • Exception migration: Per-connector exceptions to unified ConnectorException
  • Property update: ex.StatusCode to ex.Status (from RequestFailedException)
  • Remove IsFatal() guards (made internal in SDK)
  • Switch from NuGet package to project reference (pending next SDK release)

Net diff: +184 / -741 lines

Depends on

…amespace

Replace ~130 lines of manual DI boilerplate in Program.cs with SDK extension
methods (AddOffice365Client, AddTeamsClient, etc.).

Changes:
- Program.cs: Replace 10 factory registrations with 9 one-liner extension calls
- Remove Configuration/ConnectorOptions.cs (no longer needed)
- Remove AzureLogAnalyticsFunctions.cs (connector deprecated in SDK)
- Update namespaces: Microsoft.Azure.Connectors.DirectClient.* -> Azure.Connectors.Sdk.*
- Update exception types: per-connector exceptions -> unified ConnectorException
- Update exception property: StatusCode -> Status (from RequestFailedException)
- Remove IsFatal() guards (made internal in SDK)
- Switch from NuGet package to project reference (pending next SDK release)

Depends on: Azure/Connectors-NET-SDK#117
Copilot AI review requested due to automatic review settings May 7, 2026 17:40
@daviburg daviburg requested a review from a team as a code owner May 7, 2026 17:40
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

This PR updates the DirectConnector sample to use the new Azure Connectors SDK DI extension methods (reducing DI boilerplate), migrates code to the Azure.Connectors.Sdk.* namespaces, and aligns error handling with the SDK’s unified ConnectorException.

Changes:

  • Replaced manual connector client DI registrations with SDK-provided Add*Client(...) extension methods.
  • Migrated connector namespaces/exceptions to Azure.Connectors.Sdk.* and ConnectorException (including StatusCodeStatus).
  • Removed legacy per-connector configuration options class and removed the deprecated Azure Log Analytics sample functions.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
DirectConnector/Program.cs Switches connector client DI wiring to SDK DI extension methods driven by config sections.
DirectConnector/DirectConnector.csproj Replaces the SDK NuGet dependency with a project reference (currently pointing outside the repo).
DirectConnector/ConnectorFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/OneDriveFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/Office365UsersFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/MsGraphFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/MqFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/SmtpFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/AzureBlobFunctions.cs Migrates connector namespaces and exception handling to ConnectorException/Status.
DirectConnector/ConnectorTriggerMetadataAttribute.cs Updates XML doc references to the new SDK namespace.
DirectConnector/Configuration/ConnectorOptions.cs Removed (legacy options binding/validation path).
DirectConnector/AzureLogAnalyticsFunctions.cs Removed (connector deprecated/removed in the SDK).

Comment thread DirectConnector/DirectConnector.csproj Outdated
Comment thread DirectConnector/SmtpFunctions.cs Outdated
Comment thread DirectConnector/OneDriveFunctions.cs Outdated
Comment thread DirectConnector/AzureBlobFunctions.cs Outdated
Comment thread DirectConnector/MqFunctions.cs Outdated
Comment thread DirectConnector/MsGraphFunctions.cs Outdated
Comment thread DirectConnector/Office365UsersFunctions.cs Outdated
Comment thread DirectConnector/ConnectorFunctions.cs Outdated
- Replace cross-repo ProjectReference with NuGet PackageReference (0.9.0-preview.1)
- Add 'when (ex is not OperationCanceledException)' filter to all catch-all blocks
  to preserve cancellation propagation and avoid catching fatal exceptions
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 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread DirectConnector/DirectConnector.csproj 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 12 out of 12 changed files in this pull request and generated no new comments.

@daviburg daviburg marked this pull request as draft May 7, 2026 18:51
@daviburg
Copy link
Copy Markdown
Member Author

daviburg commented May 7, 2026

[Dobby] Converted to draft — this PR depends on Azure/Connectors-NET-SDK#117 being merged and published as \Azure.Connectors.Sdk\ 0.9.0-preview.1 to nuget.org. CI will fail with \NU1101: Unable to find package Azure.Connectors.Sdk\ until then. Mark as ready for review after the SDK release.

@daviburg
Copy link
Copy Markdown
Member Author

daviburg commented May 8, 2026

Closing — superseded by #40 which consolidates all SDK v0.9.0-preview.1 breaking changes, namespace migrations, and new features into a single PR.

@daviburg daviburg closed this May 8, 2026
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.

2 participants