diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs
deleted file mode 100644
index e0555172..00000000
--- a/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- * See https://github.com/openiddict/openiddict-core for more information concerning
- * the license and the contributors participating to this project.
- */
-
-using System.Runtime.CompilerServices;
-
-namespace MongoDB.Driver;
-
-///
-/// Exposes extensions simplifying the integration between OpenIddict and MongoDB.
-///
-internal static class OpenIddictMongoDbHelpers
-{
- ///
- /// Executes the query and returns the results as a streamed async enumeration.
- ///
- /// The type of the returned entities.
- /// The query source.
- /// The that can be used to abort the operation.
- /// The streamed async enumeration containing the results.
- internal static IAsyncEnumerable ToAsyncEnumerable(this IAsyncCursorSource source, CancellationToken cancellationToken)
- {
- ArgumentNullException.ThrowIfNull(source);
-
- return ExecuteAsync(source, cancellationToken);
-
- static async IAsyncEnumerable ExecuteAsync(IAsyncCursorSource source, [EnumeratorCancellation] CancellationToken cancellationToken)
- {
- using var cursor = await source.ToCursorAsync(cancellationToken);
-
- while (await cursor.MoveNextAsync(cancellationToken))
- {
- foreach (var element in cursor.Current)
- {
- yield return element;
- }
- }
- }
- }
-
- ///
- /// Executes the query and returns the results as a streamed async enumeration.
- ///
- /// The type of the returned entities.
- /// The query source.
- /// The that can be used to abort the operation.
- /// The streamed async enumeration containing the results.
- internal static IAsyncEnumerable ToAsyncEnumerable(this IQueryable source, CancellationToken cancellationToken)
- {
- ArgumentNullException.ThrowIfNull(source);
-
- return ((IAsyncCursorSource) source).ToAsyncEnumerable(cancellationToken);
- }
-}
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs
index bbd2048a..2d84c50b 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs
@@ -151,7 +151,7 @@ public class OpenIddictMongoDbApplicationStore<
var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName);
await foreach (var application in collection.Find(application =>
- application.PostLogoutRedirectUris!.Contains(uri)).ToAsyncEnumerable(cancellationToken))
+ application.PostLogoutRedirectUris!.Contains(uri)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return application;
}
@@ -172,7 +172,7 @@ public class OpenIddictMongoDbApplicationStore<
var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName);
await foreach (var application in collection.Find(application =>
- application.RedirectUris!.Contains(uri)).ToAsyncEnumerable(cancellationToken))
+ application.RedirectUris!.Contains(uri)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return application;
}
@@ -364,7 +364,7 @@ public class OpenIddictMongoDbApplicationStore<
query = query.Take(count.Value);
}
- await foreach (var application in ((IAsyncCursorSource) query).ToAsyncEnumerable(cancellationToken))
+ await foreach (var application in ((IAsyncCursorSource) query).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return application;
}
@@ -384,7 +384,7 @@ public class OpenIddictMongoDbApplicationStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.ApplicationsCollectionName);
- await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable(cancellationToken))
+ await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return element;
}
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
index d361008c..511ed63c 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs
@@ -146,7 +146,7 @@ public class OpenIddictMongoDbAuthorizationStore<
query = query.Where(authorization => Enumerable.All(values, scope => authorization.Scopes!.Contains(scope)));
}
- await foreach (var authorization in query.ToAsyncEnumerable(cancellationToken))
+ await foreach (var authorization in query.ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return authorization;
}
@@ -166,7 +166,7 @@ public class OpenIddictMongoDbAuthorizationStore<
var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName);
await foreach (var authorization in collection.Find(authorization =>
- authorization.ApplicationId == ObjectId.Parse(identifier)).ToAsyncEnumerable(cancellationToken))
+ authorization.ApplicationId == ObjectId.Parse(identifier)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return authorization;
}
@@ -199,7 +199,7 @@ public class OpenIddictMongoDbAuthorizationStore<
var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName);
await foreach (var authorization in collection.Find(authorization =>
- authorization.Subject == subject).ToAsyncEnumerable(cancellationToken))
+ authorization.Subject == subject).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return authorization;
}
@@ -330,7 +330,7 @@ public class OpenIddictMongoDbAuthorizationStore<
query = query.Take(count.Value);
}
- await foreach (var authorization in ((IAsyncCursorSource) query).ToAsyncEnumerable(cancellationToken))
+ await foreach (var authorization in ((IAsyncCursorSource) query).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return authorization;
}
@@ -350,7 +350,7 @@ public class OpenIddictMongoDbAuthorizationStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.AuthorizationsCollectionName);
- await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable(cancellationToken))
+ await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return element;
}
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs
index be31f8a2..1ddf5b88 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbResourceStore.cs
@@ -142,7 +142,7 @@ public class OpenIddictMongoDbResourceStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.ResourcesCollectionName);
- await foreach (var resource in collection.Find(resource => names.Contains(resource.Name!)).ToAsyncEnumerable(cancellationToken))
+ await foreach (var resource in collection.Find(resource => names.Contains(resource.Name!)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return resource;
}
@@ -269,7 +269,7 @@ public class OpenIddictMongoDbResourceStore<
query = query.Take(count.Value);
}
- await foreach (var resource in ((IAsyncCursorSource) query).ToAsyncEnumerable(cancellationToken))
+ await foreach (var resource in ((IAsyncCursorSource) query).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return resource;
}
@@ -289,7 +289,7 @@ public class OpenIddictMongoDbResourceStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.ResourcesCollectionName);
- await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable(cancellationToken))
+ await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return element;
}
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs
index 5f6ea031..7d41778b 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs
@@ -142,7 +142,7 @@ public class OpenIddictMongoDbScopeStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName);
- await foreach (var scope in collection.Find(scope => names.Contains(scope.Name!)).ToAsyncEnumerable(cancellationToken))
+ await foreach (var scope in collection.Find(scope => names.Contains(scope.Name!)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return scope;
}
@@ -161,7 +161,7 @@ public class OpenIddictMongoDbScopeStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName);
- await foreach (var scope in collection.Find(scope => scope.Resources!.Contains(resource)).ToAsyncEnumerable(cancellationToken))
+ await foreach (var scope in collection.Find(scope => scope.Resources!.Contains(resource)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return scope;
}
@@ -296,7 +296,7 @@ public class OpenIddictMongoDbScopeStore<
query = query.Take(count.Value);
}
- await foreach (var scope in ((IAsyncCursorSource) query).ToAsyncEnumerable(cancellationToken))
+ await foreach (var scope in ((IAsyncCursorSource) query).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return scope;
}
@@ -316,7 +316,7 @@ public class OpenIddictMongoDbScopeStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.ScopesCollectionName);
- await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable(cancellationToken))
+ await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return element;
}
diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs
index 07bffcd4..59b6c74d 100644
--- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs
+++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs
@@ -134,7 +134,7 @@ public class OpenIddictMongoDbTokenStore<
query = query.Where(token => token.Type == type);
}
- await foreach (var token in query.ToAsyncEnumerable(cancellationToken))
+ await foreach (var token in query.ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return token;
}
@@ -153,7 +153,7 @@ public class OpenIddictMongoDbTokenStore<
var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName);
await foreach (var token in collection.Find(token =>
- token.ApplicationId == ObjectId.Parse(identifier)).ToAsyncEnumerable(cancellationToken))
+ token.ApplicationId == ObjectId.Parse(identifier)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return token;
}
@@ -173,7 +173,7 @@ public class OpenIddictMongoDbTokenStore<
var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName);
await foreach (var token in collection.Find(token =>
- token.AuthorizationId == ObjectId.Parse(identifier)).ToAsyncEnumerable(cancellationToken))
+ token.AuthorizationId == ObjectId.Parse(identifier)).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return token;
}
@@ -214,7 +214,7 @@ public class OpenIddictMongoDbTokenStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName);
- await foreach (var token in collection.Find(token => token.Subject == subject).ToAsyncEnumerable(cancellationToken))
+ await foreach (var token in collection.Find(token => token.Subject == subject).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return token;
}
@@ -377,7 +377,7 @@ public class OpenIddictMongoDbTokenStore<
query = query.Take(count.Value);
}
- await foreach (var token in ((IAsyncCursorSource) query).ToAsyncEnumerable(cancellationToken))
+ await foreach (var token in ((IAsyncCursorSource) query).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return token;
}
@@ -397,7 +397,7 @@ public class OpenIddictMongoDbTokenStore<
var database = await Context.GetDatabaseAsync(cancellationToken);
var collection = database.GetCollection(Options.CurrentValue.TokensCollectionName);
- await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable(cancellationToken))
+ await foreach (var element in query(collection.AsQueryable(), state).ToAsyncEnumerable().WithCancellation(cancellationToken))
{
yield return element;
}