diff --git a/Polly.sln b/Polly.sln index 92a68a4c3c7..fdaf8064e5d 100644 --- a/Polly.sln +++ b/Polly.sln @@ -29,9 +29,14 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "eng", "eng", "{04E3C7C5-31F7-4CD6-8BEC-C1032527D231}" ProjectSection(SolutionItems) = preProject eng\Analyzers.targets = eng\Analyzers.targets + eng\Benchmark.targets = eng\Benchmark.targets + eng\bump-version.ps1 = eng\bump-version.ps1 eng\Common.targets = eng\Common.targets eng\Library.targets = eng\Library.targets + eng\stryker-config.json = eng\stryker-config.json eng\Test.targets = eng\Test.targets + eng\update-baselines.ps1 = eng\update-baselines.ps1 + eng\update-changelog.ps1 = eng\update-changelog.ps1 EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polly.Core.Benchmarks", "bench\Polly.Core.Benchmarks\Polly.Core.Benchmarks.csproj", "{CC306C35-E3BC-4F0B-AB8C-B9D4C82DC3DE}" diff --git a/build.cake b/build.cake index 13173854b06..8d92a5465d5 100644 --- a/build.cake +++ b/build.cake @@ -9,8 +9,8 @@ var configuration = Argument("configuration", "Release"); // EXTERNAL NUGET TOOLS ////////////////////////////////////////////////////////////////////// -#Tool "xunit.runner.console&version=2.8.1" -#Tool "dotnet-stryker&version=4.0.6" +#Tool "xunit.runner.console&version=2.9.2" +#Tool "dotnet-stryker&version=4.2.0" ////////////////////////////////////////////////////////////////////// // EXTERNAL NUGET LIBRARIES diff --git a/eng/stryker-config.json b/eng/stryker-config.json index 02ac44f8f01..fe485b07db4 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -18,6 +18,7 @@ "block", "statement" ], + "configuration": "Debug", "target-framework": "net8.0", "thresholds": { "high": 100, 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 2265d3c10a2..9641131d07c 100644 --- a/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs +++ b/test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NSubstitute; -using Polly.DependencyInjection; using Polly.Registry; using Polly.Telemetry; @@ -20,18 +19,23 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) var resList = new List(); var reloadableConfig = new ReloadableConfiguration(); reloadableConfig.Reload(new() { { "tag", "initial-tag" } }); - var builder = new ConfigurationBuilder().Add(reloadableConfig); var fakeListener = new FakeTelemetryListener(); + var configuration = new ConfigurationBuilder() + .Add(reloadableConfig) + .Build(); + var services = new ServiceCollection(); if (name == null) { - services.Configure(builder.Build()); + services.Configure(configuration) + .Configure(options => options.OptionsName = name); } else { - services.Configure(name, builder.Build()); + services.Configure(name, configuration) + .Configure(name, options => options.OptionsName = name); } services.Configure(options => options.TelemetryListeners.Add(fakeListener)); @@ -40,6 +44,9 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) builder.InstanceName = "my-instance"; var options = context.GetOptions(name); + options.Should().NotBeNull(); + options.OptionsName.Should().Be(name); + context.EnableReloads(name); builder.AddStrategy(_ => @@ -48,7 +55,7 @@ public void AddResiliencePipeline_EnsureReloadable(string? name) resList.Add(res); return new ReloadableStrategy(options.Tag, res); }, - new ReloadableStrategyOptions()); + options); }); var serviceProvider = services.BuildServiceProvider(); @@ -115,6 +122,8 @@ protected override ValueTask> ExecuteCore( public class ReloadableStrategyOptions : ResilienceStrategyOptions { public string Tag { get; set; } = string.Empty; + + public string? OptionsName { get; set; } } private class ReloadableConfiguration : ConfigurationProvider, IConfigurationSource