Skip to content

feat(extensions): add EnableReloads overload accepting custom IOptionsMonitor#3140

Open
arashzjahangiri wants to merge 2 commits into
App-vNext:mainfrom
arashzjahangiri:fix/enable-reloads-custom-options-monitor
Open

feat(extensions): add EnableReloads overload accepting custom IOptionsMonitor#3140
arashzjahangiri wants to merge 2 commits into
App-vNext:mainfrom
arashzjahangiri:fix/enable-reloads-custom-options-monitor

Conversation

@arashzjahangiri

@arashzjahangiri arashzjahangiri commented Jul 3, 2026

Copy link
Copy Markdown

closes #3050

Adds a new public overload of AddResiliencePipelineContext.EnableReloads that accepts a caller-supplied IOptionsMonitor directly, instead of resolving it from the DI container.

The underlying ConfigureBuilderContextExtensions.EnableReloads already accepts the monitor directly - this change surfaces that path through the public API.

Use cases enabled:

  • Custom options systems outside Microsoft.Extensions.Options
  • Wrapping alternative configuration sources (feature flags, remote configs)
  • Sharing monitor instances across pipelines without DI registration

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

…sMonitor

Closes App-vNext#3050

Adds a new public overload of AddResiliencePipelineContext<TKey>.EnableReloads<TOptions>
that accepts a caller-supplied IOptionsMonitor<TOptions> directly, instead of resolving
it from the DI container.

The underlying ConfigureBuilderContextExtensions.EnableReloads already accepts the
monitor directly - this change surfaces that path through the public API.

Use cases enabled:
- Custom options systems outside Microsoft.Extensions.Options
- Wrapping alternative configuration sources (feature flags, remote configs)
- Sharing monitor instances across pipelines without DI registration
using Polly.Registry;
using Polly.Utils;

#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters

@martincostello martincostello Jul 8, 2026

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.

Please rework the API to remove the need to suppress this warning.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Reworked the API to avoid the RS0026 suppression entirely. The new IOptionsMonitor overload no longer has an optional name parameter — instead there are two explicit overloads: one with just the monitor, and one with both monitor and name. The original EnableReloads<TOptions>(string? name = null) remains unchanged (no breaking change). The RS0027 that appears on the original overload (a consequence of adding a 2-param sibling) is suppressed with a targeted pragma/restore pair on that method only, consistent with the pattern already used in Polly.Core.

#nullable enable
abstract Polly.Telemetry.MeteringEnricher.Enrich<TResult, TArgs>(in Polly.Telemetry.EnrichmentContext<TResult, TArgs> context) -> void
Polly.DependencyInjection.AddResiliencePipelineContext<TKey>
Polly.DependencyInjection.AddResiliencePipelineContext<TKey>.EnableReloads<TOptions>(string? name = null) -> void

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.

This is a breaking change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I reverted this change.

…suppressions

Replace the file-level RS0026 suppression with an API design that needs no suppression:
- Keep the shipped EnableReloads<TOptions>(string? name = null) overload unchanged
- Add EnableReloads<TOptions>(IOptionsMonitor<TOptions> monitor) (no-name convenience)
- Add EnableReloads<TOptions>(IOptionsMonitor<TOptions> monitor, string? name) without
  optional parameter, eliminating the RS0026 violation
- Add a targeted RS0027 suppress/restore around the original overload only, consistent
  with the pattern used in Polly.Core for the same constraint
@arashzjahangiri arashzjahangiri force-pushed the fix/enable-reloads-custom-options-monitor branch from c52d8f8 to a260473 Compare July 9, 2026 08:42
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.

[Feature request]: Expose EnableReloads overload that accepts a custom IOptionsMonitor<TOptions> instance

2 participants