Skip to content

Commit 52b6806

Browse files
committed
PR feedback: Don't require IDistributedCache in DI
1 parent 9faa3a7 commit 52b6806

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/ModelContextProtocol.AspNetCore/DistributedCacheEventStreamStoreOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ModelContextProtocol.AspNetCore;
88
/// Configures <see cref="DistributedCacheEventStreamStoreOptions"/> by resolving
99
/// the <see cref="IDistributedCache"/> from DI when not explicitly set.
1010
/// </summary>
11-
internal sealed class DistributedCacheEventStreamStoreOptionsSetup(IDistributedCache cache) : IConfigureOptions<DistributedCacheEventStreamStoreOptions>
11+
internal sealed class DistributedCacheEventStreamStoreOptionsSetup(IDistributedCache? cache = null) : IConfigureOptions<DistributedCacheEventStreamStoreOptions>
1212
{
1313
public void Configure(DistributedCacheEventStreamStoreOptions options)
1414
{

tests/ModelContextProtocol.AspNetCore.Tests/HttpMcpServerBuilderExtensionsTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.Caching.Distributed;
3+
using Microsoft.Extensions.Caching.Memory;
24
using Microsoft.Extensions.DependencyInjection;
35
using Microsoft.Extensions.Options;
46
using ModelContextProtocol.AspNetCore.Tests.Utils;
@@ -43,6 +45,22 @@ public void WithDistributedCacheEventStreamStore_ConfigureCallbackIsInvoked()
4345
Assert.NotNull(capturedOptions);
4446
}
4547

48+
[Fact]
49+
public void WithDistributedCacheEventStreamStore_WorksWithoutDICache_WhenCacheSetViaCallback()
50+
{
51+
var explicitCache = new MemoryDistributedCache(Options.Create(new MemoryDistributedCacheOptions()));
52+
53+
Builder.Services
54+
.AddMcpServer()
55+
.WithHttpTransport()
56+
.WithDistributedCacheEventStreamStore(options => options.Cache = explicitCache);
57+
58+
using var app = Builder.Build();
59+
60+
var store = app.Services.GetService<ISseEventStreamStore>();
61+
Assert.IsType<DistributedCacheEventStreamStore>(store);
62+
}
63+
4664
[Fact]
4765
public void EventStreamStore_IsPopulatedFromDI_ViaPostConfigure()
4866
{

0 commit comments

Comments
 (0)