11using Microsoft . AspNetCore . Authorization ;
22using Microsoft . Extensions . Caching . Distributed ;
33using Microsoft . Extensions . DependencyInjection . Extensions ;
4- using Microsoft . Extensions . Logging ;
54using Microsoft . Extensions . Options ;
65using ModelContextProtocol . AspNetCore ;
76using ModelContextProtocol . Server ;
@@ -69,8 +68,7 @@ public static IMcpServerBuilder AddAuthorizationFilters(this IMcpServerBuilder b
6968 }
7069
7170 /// <summary>
72- /// Registers a <see cref="DistributedCacheEventStreamStore"/> as the <see cref="ISseEventStreamStore"/> for SSE resumability,
73- /// using the <see cref="IDistributedCache"/> already registered in the service collection.
71+ /// Registers a <see cref="DistributedCacheEventStreamStore"/> as the <see cref="ISseEventStreamStore"/> for SSE resumability.
7472 /// </summary>
7573 /// <param name="builder">The builder instance.</param>
7674 /// <param name="configureOptions">An optional action to configure <see cref="DistributedCacheEventStreamStoreOptions"/>.</param>
@@ -79,41 +77,19 @@ public static IMcpServerBuilder AddAuthorizationFilters(this IMcpServerBuilder b
7977 /// <remarks>
8078 /// <para>
8179 /// An <see cref="IDistributedCache"/> implementation must be registered in the service collection before calling this method.
82- /// For example, call <c>builder.Services.AddDistributedMemoryCache()</c> for an in-memory cache or
83- /// <c>builder.Services.AddStackExchangeRedisCache(...)</c> for Redis.
80+ /// The registered cache is automatically assigned to <see cref="DistributedCacheEventStreamStoreOptions.Cache"/>.
8481 /// </para>
8582 /// <para>
8683 /// To use a specific <see cref="IDistributedCache"/> instance instead of the one registered in DI,
87- /// use the overload that accepts an <see cref="IDistributedCache "/> parameter .
84+ /// set the <see cref="DistributedCacheEventStreamStoreOptions.Cache"/> property in the <paramref name="configureOptions "/> callback .
8885 /// </para>
8986 /// </remarks>
9087 public static IMcpServerBuilder WithDistributedCacheEventStreamStore ( this IMcpServerBuilder builder , Action < DistributedCacheEventStreamStoreOptions > ? configureOptions = null )
91- => builder . WithDistributedCacheEventStreamStore ( cache : null , configureOptions ) ;
92-
93- /// <summary>
94- /// Registers a <see cref="DistributedCacheEventStreamStore"/> as the <see cref="ISseEventStreamStore"/> for SSE resumability,
95- /// using the specified <see cref="IDistributedCache"/>.
96- /// </summary>
97- /// <param name="builder">The builder instance.</param>
98- /// <param name="cache">The <see cref="IDistributedCache"/> to use for event storage, or <see langword="null"/> to resolve from DI.</param>
99- /// <param name="configureOptions">An optional action to configure <see cref="DistributedCacheEventStreamStoreOptions"/>.</param>
100- /// <returns>The builder provided in <paramref name="builder"/>.</returns>
101- /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
102- /// <remarks>
103- /// Use this overload when you have multiple <see cref="IDistributedCache"/> implementations or want to
104- /// use a specific instance rather than the one registered in DI.
105- /// </remarks>
106- public static IMcpServerBuilder WithDistributedCacheEventStreamStore ( this IMcpServerBuilder builder , IDistributedCache ? cache , Action < DistributedCacheEventStreamStoreOptions > ? configureOptions = null )
10788 {
10889 ArgumentNullException . ThrowIfNull ( builder ) ;
10990
110- builder . Services . AddSingleton < ISseEventStreamStore > ( sp =>
111- {
112- var resolvedCache = cache ?? sp . GetRequiredService < IDistributedCache > ( ) ;
113- var options = sp . GetService < IOptions < DistributedCacheEventStreamStoreOptions > > ( ) ? . Value ;
114- var logger = sp . GetService < ILogger < DistributedCacheEventStreamStore > > ( ) ;
115- return new DistributedCacheEventStreamStore ( resolvedCache , options , logger ) ;
116- } ) ;
91+ builder . Services . TryAddEnumerable ( ServiceDescriptor . Singleton < IConfigureOptions < DistributedCacheEventStreamStoreOptions > , DistributedCacheEventStreamStoreOptionsSetup > ( ) ) ;
92+ builder . Services . AddSingleton < ISseEventStreamStore , DistributedCacheEventStreamStore > ( ) ;
11793
11894 if ( configureOptions is not null )
11995 {
0 commit comments