diff --git a/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs b/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs index 8d358b45f11..a7b6ffe3729 100644 --- a/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs +++ b/src/Polly.Extensions/DependencyInjection/AddResiliencePipelineContext.cs @@ -61,8 +61,7 @@ internal AddResiliencePipelineContext(ConfigureBuilderContext registryCont public TOptions GetOptions<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions>(string? name = null) { var monitor = ServiceProvider.GetRequiredService>(); - - return name == null ? monitor.CurrentValue : monitor.Get(name); + return monitor.Get(name); } /// diff --git a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs index b4dacecc990..0f0d098622d 100644 --- a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs +++ b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs @@ -29,11 +29,13 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) if (name == null) { - services.Configure(configuration); + services.Configure(configuration) + .Configure(options => options.Name = name); } else { - services.Configure(name, configuration); + services.Configure(name, configuration) + .Configure(name, options => options.Name = name); } services.Configure(options => options.TelemetryListeners.Add(fakeListener)); @@ -43,6 +45,7 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) var options = context.GetOptions(name); options.Should().NotBeNull(); + options.Name.Should().Be(name); context.EnableReloads(name); @@ -119,6 +122,8 @@ protected override ValueTask> ExecuteCore( public class ReloadableStrategyOptions : ResilienceStrategyOptions { public string Tag { get; set; } = string.Empty; + + public string? Name { get; set; } } private class ReloadableConfiguration : ConfigurationProvider, IConfigurationSource