Skip to content

Add validation to UseDisabledWhen() for correct call ordering - #3

Closed
Anders-Toegersen with Copilot wants to merge 3 commits into
mainfrom
copilot/sub-pr-2
Closed

Anders-Toegersen with Copilot wants to merge 3 commits into
mainfrom
copilot/sub-pr-2

Conversation

Copilot AI commented Feb 18, 2026 •

Copy link
Copy Markdown

The UseDisabledWhen() extension silently fails when called before ConfigureFunctionsWebApplication() because the Functions worker resolves the last registered IFunctionMetadataProvider, finding none if mis-ordered.

Changes

  • Validation at registration-time: Check that an underlying IFunctionMetadataProvider exists in the service collection before registering DisabledWhenMetadataProvider
  • Clear error message: Throw InvalidOperationException specifying that UseDisabledWhen() must be called after ConfigureFunctionsWebApplication() or ConfigureFunctionsWorkerDefaults()

Example

// ❌ This now throws immediately with clear error:
var builder = new HostBuilder();
builder.UseDisabledWhen();  // InvalidOperationException

// ✅ Correct ordering still works:
var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .UseDisabledWhen()  // Validation passes
    .Build();

This ensures fail-fast behavior at startup instead of runtime failures when the host attempts to resolve metadata providers.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…reFunctionsWebApplication

Co-authored-by: Anders-Toegersen <54847232+Anders-Toegersen@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback from review on prerelease 1.0.1 PR Add validation to UseDisabledWhen() for correct call ordering Feb 18, 2026
@Anders-Toegersen

Copy link
Copy Markdown
Owner

fixed in main

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