Skip to content

Conversation

@brettsam
Copy link
Member

@brettsam brettsam commented Dec 5, 2025

Fixes #1301

Both the AspNet and App Insights packages had some issues with calling Configure...() multiple times. This prevents the issues by checking and bailing early if a method has already been called to register services.

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

Copilot AI review requested due to automatic review settings December 5, 2025 17:45
Copy link
Contributor

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 improves the idempotency of registration methods for both AspNet Core integration and Application Insights packages, addressing issue #1301. The changes ensure that calling configuration methods multiple times doesn't result in duplicate service registrations or errors.

Key Changes:

  • Implemented idempotency checks in configuration methods using different strategies: IHostBuilder.Properties sentinel values and IServiceCollection.Any() checks
  • Changed WorkerOptions.Capabilities from using Add() to indexer syntax to prevent duplicate key exceptions
  • Added comprehensive tests to verify idempotent behavior while ensuring user callbacks are still invoked each time

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
extensions/Worker.Extensions.Http.AspNetCore/src/FunctionsHostBuilderExtensions.cs Added idempotency check using IHostBuilder.Properties with sentinel key to prevent duplicate service registration
extensions/Worker.Extensions.Http.AspNetCore/src/WorkerBuilderExtensions.cs Added idempotency check using ServiceCollection.Any() and changed Capabilities.Add() to indexer syntax
src/DotNetWorker.ApplicationInsights/FunctionsApplicationInsightsExtensions.cs Added idempotency check using ServiceCollection.Any() to detect marker service
test/extensions/Worker.Extensions.Http.AspNetCore.Tests/FunctionsHostBuilderExtensionsTests.cs Added test verifying idempotent behavior with multiple calls while ensuring callbacks execute each time
test/DotNetWorker.Tests/ApplicationInsights/ApplicationInsightsConfigurationTests.cs Added count assertions to verify services are only registered once despite multiple configuration calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@brettsam brettsam merged commit 1bea07e into main Dec 10, 2025
30 checks passed
@brettsam brettsam deleted the brettsam/idempotent branch December 10, 2025 15:41
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.

Missing HostBuilder startup logging/validation

3 participants