Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Polly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var configuration = Argument<string>("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.3.0"

//////////////////////////////////////////////////////////////////////
// EXTERNAL NUGET LIBRARIES
Expand Down
1 change: 1 addition & 0 deletions eng/stryker-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"block",
"statement"
],
"configuration": "Debug",
"target-framework": "net8.0",
"thresholds": {
"high": 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ internal AddResiliencePipelineContext(ConfigureBuilderContext<TKey> registryCont
public TOptions GetOptions<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions>(string? name = null)
{
var monitor = ServiceProvider.GetRequiredService<IOptionsMonitor<TOptions>>();

return name == null ? monitor.CurrentValue : monitor.Get(name);
return monitor.Get(name);
Copy link
Member Author

Choose a reason for hiding this comment

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

Effectively duplicates the implementation the way it was.

}

/// <summary>
Expand Down
19 changes: 14 additions & 5 deletions test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Polly.DependencyInjection;
using Polly.Registry;
using Polly.Telemetry;

Expand All @@ -20,18 +19,23 @@ public void AddResiliencePipeline_EnsureReloadable(string? name)
var resList = new List<IDisposable>();
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<ReloadableStrategyOptions>(builder.Build());
services.Configure<ReloadableStrategyOptions>(configuration)
.Configure<ReloadableStrategyOptions>(options => options.OptionsName = name);
}
else
{
services.Configure<ReloadableStrategyOptions>(name, builder.Build());
services.Configure<ReloadableStrategyOptions>(name, configuration)
.Configure<ReloadableStrategyOptions>(name, options => options.OptionsName = name);
}

services.Configure<TelemetryOptions>(options => options.TelemetryListeners.Add(fakeListener));
Expand All @@ -40,6 +44,9 @@ public void AddResiliencePipeline_EnsureReloadable(string? name)
builder.InstanceName = "my-instance";

var options = context.GetOptions<ReloadableStrategyOptions>(name);
options.Should().NotBeNull();
options.OptionsName.Should().Be(name);

context.EnableReloads<ReloadableStrategyOptions>(name);

builder.AddStrategy(_ =>
Expand All @@ -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();
Expand Down Expand Up @@ -115,6 +122,8 @@ protected override ValueTask<Outcome<TResult>> ExecuteCore<TResult, TState>(
public class ReloadableStrategyOptions : ResilienceStrategyOptions
{
public string Tag { get; set; } = string.Empty;

public string? OptionsName { get; set; }
}

private class ReloadableConfiguration : ConfigurationProvider, IConfigurationSource
Expand Down