File tree Expand file tree Collapse file tree
src/ModelContextProtocol.AspNetCore
tests/ModelContextProtocol.AspNetCore.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 11using Microsoft . AspNetCore . Http ;
2+ using Microsoft . Extensions . Caching . Distributed ;
3+ using Microsoft . Extensions . Caching . Memory ;
24using Microsoft . Extensions . DependencyInjection ;
35using Microsoft . Extensions . Options ;
46using 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 {
You can’t perform that action at this time.
0 commit comments