Added cancellation tokens (ongoing)

This commit is contained in:
Alexandre SPIESER
2021-03-10 08:44:50 +00:00
parent e4a36e5c60
commit 658c753989
10 changed files with 161 additions and 101 deletions
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace MongoDbGenericRepository
@@ -49,11 +50,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="id">The Id of the document you want to get.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null)
/// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetByIdAsync<TDocument, TKey>(TKey id, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbReader.GetByIdAsync<TDocument, TKey>(id, partitionKey);
return await MongoDbReader.GetByIdAsync<TDocument, TKey>(id, partitionKey, cancellationToken);
}
/// <summary>
@@ -77,11 +79,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
/// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<TDocument> GetOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbReader.GetOneAsync<TDocument, TKey>(filter, partitionKey);
return await MongoDbReader.GetOneAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
}
/// <summary>
@@ -119,11 +122,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
/// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<bool> AnyAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbReader.AnyAsync<TDocument, TKey>(filter, partitionKey);
return await MongoDbReader.AnyAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
}
/// <summary>
@@ -147,11 +151,12 @@ namespace MongoDbGenericRepository
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">A LINQ expression filter.</param>
/// <param name="partitionKey">An optional partition key.</param>
public async virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
/// <param name="cancellationToken">An optional cancellation Token.</param>
public async virtual Task<List<TDocument>> GetAllAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null, CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return await MongoDbReader.GetAllAsync<TDocument, TKey>(filter, partitionKey);
return await MongoDbReader.GetAllAsync<TDocument, TKey>(filter, partitionKey, cancellationToken);
}
/// <summary>