Skip to content

Commit 7c915d4

Browse files
committed
remove IOptions<T> from RedisOutputCacheOptions (required using DI in the tests)
1 parent b92051a commit 7c915d4

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/src/RedisOutputCacheOptions.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.OutputCaching.StackExchangeRedis;
1313
/// <summary>
1414
/// Configuration options for Redis based output cache.
1515
/// </summary>
16-
public sealed class RedisOutputCacheOptions : IOptions<RedisOutputCacheOptions>
16+
public sealed class RedisOutputCacheOptions
1717
{
1818
/// <summary>
1919
/// The configuration used to connect to Redis.
@@ -42,11 +42,6 @@ public sealed class RedisOutputCacheOptions : IOptions<RedisOutputCacheOptions>
4242
/// </summary>
4343
public Func<ProfilingSession>? ProfilingSession { get; set; }
4444

45-
RedisOutputCacheOptions IOptions<RedisOutputCacheOptions>.Value
46-
{
47-
get { return this; }
48-
}
49-
5045
private bool? _useForceReconnect;
5146
internal bool UseForceReconnect
5247
{

src/Middleware/Microsoft.AspNetCore.OutputCaching.StackExchangeRedis/test/OutputCacheGetSetTests.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Buffers;
55
using System.IO.Pipelines;
6+
using Microsoft.Extensions.DependencyInjection;
67
using StackExchange.Redis;
78
using Xunit.Abstractions;
89

@@ -20,16 +21,19 @@ public class OutputCacheGetSetTests : IClassFixture<RedisConnectionFixture>
2021

2122
public OutputCacheGetSetTests(RedisConnectionFixture connection, ITestOutputHelper log)
2223
{
24+
// use DI to get the configured service, but tweak the GC mode
2325
_fixture = connection;
24-
_cache = new RedisOutputCacheStore(new RedisOutputCacheOptions
25-
{
26-
ConnectionMultiplexerFactory = () => Task.FromResult(_fixture.Connection),
27-
InstanceName = "TestPrefix",
28-
})
29-
{
30-
GarbageCollectionEnabled = false,
31-
};
3226
Log = log;
27+
var services = new ServiceCollection();
28+
services.AddStackExchangeRedisOutputCache(options => {
29+
options.ConnectionMultiplexerFactory = () => Task.FromResult(_fixture.Connection);
30+
options.InstanceName = "TestPrefix";
31+
});
32+
var svc = Assert.IsAssignableFrom<RedisOutputCacheStore>(
33+
services.BuildServiceProvider().GetService<IOutputCacheStore>());
34+
Assert.NotNull(svc);
35+
svc.GarbageCollectionEnabled = false;
36+
_cache = svc;
3337
}
3438

3539
#if DEBUG

0 commit comments

Comments
 (0)