diff --git a/CoreIntegrationTests/CoreIntegrationTests.csproj b/CoreIntegrationTests/CoreIntegrationTests.csproj index 69f6379..b89f770 100644 --- a/CoreIntegrationTests/CoreIntegrationTests.csproj +++ b/CoreIntegrationTests/CoreIntegrationTests.csproj @@ -7,8 +7,8 @@ - - + + all diff --git a/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs b/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs index ddd8ff9..fba2045 100644 --- a/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs +++ b/CoreIntegrationTests/Infrastructure/MongoDbTKeyDocumentTestBase.Main.cs @@ -796,7 +796,7 @@ namespace CoreIntegrationTests.Infrastructure #region Index Management - static SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1); + static readonly SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1); [Fact] public async Task CreateTextIndexNoOptionAsync() diff --git a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs index d30bc5c..86ec936 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { + /// + /// The IBaseMongoRepository_Update interface exposing update functionality for documents with Guid Ids. + /// public interface IBaseMongoRepository_Update : IBaseMongoRepository_Update { /// diff --git a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs index 8ed2e1e..9e9223b 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseMongoRepository_Update_ClientSession.cs @@ -7,6 +7,9 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Update { + /// + /// The IBaseMongoRepository_Update_ClientSession interface exposing update functionality with a IClientSessionHandle. + /// public interface IBaseMongoRepository_Update_ClientSession { /// @@ -14,10 +17,14 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. + /// The type of the field to update. /// The client session. - /// The document with the modifications you want to persist. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -27,10 +34,14 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. + /// The type of the field to update. /// The client session. - /// The document with the modifications you want to persist. + /// The filter for the update. + /// The field to update. + /// The value of the field. + /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -40,11 +51,13 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. + /// The type of the field to update. /// The client session. /// The document to modify. - /// The update definition. + /// The field to update. + /// The value of the field. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -55,10 +68,9 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type representing a Document. /// The type of the primary key for a Document. /// The client session. - /// The document to modify. - /// The update definition. + /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -68,13 +80,11 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field to update. - /// The client session. + /// The client session. /// The document to modify. - /// The field to update. - /// The value of the field. + /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -86,11 +96,12 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type of the primary key for a Document. /// The type of the field to update. /// The client session. - /// The document to modify. + /// The filter for the update. /// The field to update. /// The value of the field. + /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -118,13 +129,12 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type representing a Document. /// The type of the primary key for a Document. /// The type of the field to update. - /// The client session. - /// The filter for the update. + /// The client session. + /// The document to modify. /// The field to update. /// The value of the field. - /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -134,14 +144,10 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field to update. /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. + /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; @@ -151,14 +157,11 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field to update. /// The client session. - /// The filter for the update. - /// The field to update. - /// The value of the field. - /// The optional partition key. + /// The document to modify. + /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable; diff --git a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs index 1c4866d..304607f 100644 --- a/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs +++ b/MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -32,7 +33,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - Task GetByIdAsync(TKey id, string partitionKey = null) + /// An optional cancellation Token. + Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -54,7 +56,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - Task GetOneAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -88,7 +91,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - Task AnyAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -110,7 +114,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - Task> GetAllAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -132,7 +137,8 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partitionKey - Task CountAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -157,9 +163,13 @@ namespace MongoDbGenericRepository /// The document type. /// The type of the primary key. /// A LINQ expression filter. - /// A property selector to order by descending. + /// A property selector to order by descending. /// An optional partitionKey. - Task GetByMaxAsync(Expression> filter, Expression> orderByDescending, string partitionKey = null) + /// An optional cancellation Token. + Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -181,9 +191,13 @@ namespace MongoDbGenericRepository /// The document type. /// The type of the primary key. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector for the minimum value you are looking for. /// An optional partitionKey. - Task GetByMinAsync(Expression> filter, Expression> orderByAscending, string partitionKey = null) + /// An optional cancellation Token. + Task GetByMinAsync(Expression> filter, + Expression> minValueSelector, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -193,9 +207,9 @@ namespace MongoDbGenericRepository /// The document type. /// The type of the primary key. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector for the minimum value you are looking for. /// An optional partitionKey. - TDocument GetByMin(Expression> filter, Expression> orderByAscending, string partitionKey = null) + TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; @@ -206,9 +220,14 @@ namespace MongoDbGenericRepository /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector for the maximum value you are looking for. /// An optional partitionKey. - Task GetMaxValueAsync(Expression> filter, Expression> orderByAscending, string partitionKey = null) + /// An optional cancellation Token. + Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -219,9 +238,9 @@ namespace MongoDbGenericRepository /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector to order by ascending. /// An optional partitionKey. - TValue GetMaxValue(Expression> filter, Expression> orderByDescending, string partitionKey = null) + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; @@ -234,7 +253,12 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -263,9 +287,11 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. + /// An optional cancellation Token. Task SumByAsync(Expression> filter, Expression> selector, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -321,10 +347,15 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The type of the primary key for a Document. /// The type representing the model you want to project to. - /// + /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// An optional cancellation Token. + Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class; @@ -349,13 +380,18 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The type of the primary key for a Document. /// The type representing the model you want to project to. - /// + /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable - where TProjection : class; + /// An optional cancellation Token. + Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; /// /// Asynchronously returns a list of projected documents matching the filter condition. @@ -450,12 +486,14 @@ namespace MongoDbGenericRepository /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation Token. Task> GetSortedPaginatedAsync( Expression> filter, SortDefinition sortDefinition, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; diff --git a/MongoDbGenericRepository/BaseMongoRepository.Create.cs b/MongoDbGenericRepository/BaseMongoRepository.Create.cs index d2b319e..70d20e5 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Create.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Create.cs @@ -2,10 +2,15 @@ using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository { + /// + /// The IBaseMongoRepository_Create interface to expose document creation functionality + /// with document having an Id of type Guid. + /// public interface IBaseMongoRepository_Create : IBaseMongoRepository_Create { /// @@ -15,7 +20,8 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The type of the primary key for a Document. /// The document you want to add. - Task AddOneAsync(TDocument document) + /// An optional cancellation Token. + Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -37,7 +43,8 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The type of the primary key for a Document. /// The documents you want to add. - Task AddManyAsync(IEnumerable documents) + /// An optional cancellation Token. + Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable; @@ -61,6 +68,10 @@ namespace MongoDbGenericRepository { private readonly object _initLock = new object(); private MongoDbCreator _mongoDbCreator; + + /// + /// The MongoDbCreator field. + /// protected virtual MongoDbCreator MongoDbCreator { get @@ -87,11 +98,12 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The type of the primary key for a Document. /// The document you want to add. - public virtual async Task AddOneAsync(TDocument document) + /// An optional cancellation Token. + public virtual async Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - await MongoDbCreator.AddOneAsync(document); + await MongoDbCreator.AddOneAsync(document, cancellationToken); } /// @@ -100,10 +112,11 @@ namespace MongoDbGenericRepository /// /// The type representing a Document. /// The document you want to add. - public virtual async Task AddOneAsync(TDocument document) + /// An optional cancellation Token. + public virtual async Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument { - await MongoDbCreator.AddOneAsync(document); + await MongoDbCreator.AddOneAsync(document, cancellationToken); } /// @@ -138,11 +151,12 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The type of the primary key for a Document. /// The documents you want to add. - public virtual async Task AddManyAsync(IEnumerable documents) + /// An optional cancellation Token. + public virtual async Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - await MongoDbCreator.AddManyAsync(documents); + await MongoDbCreator.AddManyAsync(documents, cancellationToken); } /// @@ -151,10 +165,11 @@ namespace MongoDbGenericRepository /// /// The type representing a Document. /// The documents you want to add. - public virtual async Task AddManyAsync(IEnumerable documents) + /// An optional cancellation Token. + public virtual async Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument { - await MongoDbCreator.AddManyAsync(documents); + await MongoDbCreator.AddManyAsync(documents, cancellationToken); } /// diff --git a/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs b/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs index 86d3b9b..aa661b0 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Update.ClientSession.cs @@ -18,7 +18,7 @@ namespace MongoDbGenericRepository /// The client session. /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -34,7 +34,7 @@ namespace MongoDbGenericRepository /// The client session. /// The document with the modifications you want to persist. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -51,7 +51,7 @@ namespace MongoDbGenericRepository /// The document to modify. /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -68,7 +68,7 @@ namespace MongoDbGenericRepository /// The document to modify. /// The update definition. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -87,7 +87,7 @@ namespace MongoDbGenericRepository /// The field to update. /// The value of the field. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -106,7 +106,7 @@ namespace MongoDbGenericRepository /// The field to update. /// The value of the field. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -126,7 +126,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -146,7 +146,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual async Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -166,7 +166,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -186,7 +186,7 @@ namespace MongoDbGenericRepository /// The value of the field. /// The optional partition key. /// The optional cancellation token. - /// + /// A boolean value indicating success. public virtual bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable diff --git a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs index f7a4949..eded8d5 100644 --- a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs +++ b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs @@ -7,10 +7,20 @@ using System.Linq.Expressions; namespace MongoDbGenericRepository.DataAccess.Base { + /// + /// A base class for accessing the Database and its Collections. + /// public class DataAccessBase { + /// + /// The MongoDbContext + /// protected IMongoDbContext MongoDbContext; + /// + /// The constructor of the DataAccessBase class + /// + /// public DataAccessBase(IMongoDbContext mongoDbContext) { MongoDbContext = mongoDbContext; @@ -18,6 +28,14 @@ namespace MongoDbGenericRepository.DataAccess.Base #region Utility Methods + /// + /// Gets a IMongoQueryable for a potentially partitioned document type and a filter. + /// + /// The document type. + /// The type of the primary key. + /// The filter definition. + /// The collection partition key. + /// public virtual IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -108,7 +126,6 @@ namespace MongoDbGenericRepository.DataAccess.Base LanguageOverride = indexCreationOptions.LanguageOverride, ExpireAfter = indexCreationOptions.ExpireAfter, DefaultLanguage = indexCreationOptions.DefaultLanguage, - BucketSize = indexCreationOptions.BucketSize, Bits = indexCreationOptions.Bits, Background = indexCreationOptions.Background, Version = indexCreationOptions.Version diff --git a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs index bc490c7..7847030 100644 --- a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs +++ b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs @@ -6,12 +6,20 @@ using MongoDbGenericRepository.Utils; using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Create { + /// + /// A class to insert MongoDb document. + /// public class MongoDbCreator : DataAccessBase { + /// + /// The construct of the MongoDbCreator class. + /// + /// A instance. public MongoDbCreator(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } @@ -25,12 +33,13 @@ namespace MongoDbGenericRepository.DataAccess.Create /// The type representing a Document. /// The type of the primary key for a Document. /// The document you want to add. - public virtual async Task AddOneAsync(TDocument document) + /// An optional cancellation Token. + public virtual async Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { FormatDocument(document); - await HandlePartitioned(document).InsertOneAsync(document); + await HandlePartitioned(document).InsertOneAsync(document, null, cancellationToken); } /// @@ -55,7 +64,8 @@ namespace MongoDbGenericRepository.DataAccess.Create /// The type representing a Document. /// The type of the primary key for a Document. /// The documents you want to add. - public virtual async Task AddManyAsync(IEnumerable documents) + /// An optional cancellation Token. + public virtual async Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -72,12 +82,12 @@ namespace MongoDbGenericRepository.DataAccess.Create { foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) { - await HandlePartitioned(group.FirstOrDefault()).InsertManyAsync(group.ToList()); + await HandlePartitioned(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken); } } else { - await GetCollection().InsertManyAsync(documents.ToList()); + await GetCollection().InsertManyAsync(documents.ToList(), null, cancellationToken); } } diff --git a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs index b07dc0f..832b4ae 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs @@ -6,12 +6,20 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Read { + /// + /// A class to read MongoDb document. + /// public partial class MongoDbReader : DataAccessBase { + /// + /// The construct of the MongoDbReader class. + /// + /// A instance. public MongoDbReader(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } @@ -25,12 +33,13 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - public async virtual Task GetByIdAsync(TKey id, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { var filter = Builders.Filter.Eq("Id", id); - return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken); } /// @@ -55,11 +64,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(); + return await HandlePartitioned(partitionKey).Find(filter).FirstOrDefaultAsync(cancellationToken); } /// @@ -97,11 +107,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task AnyAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - var count = await HandlePartitioned(partitionKey).CountDocumentsAsync(filter); + var count = await HandlePartitioned(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken); return (count > 0); } @@ -127,11 +138,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(); + return await HandlePartitioned(partitionKey).Find(filter).ToListAsync(cancellationToken); } /// @@ -155,11 +167,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partitionKey - public async virtual Task CountAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await HandlePartitioned(partitionKey).CountDocumentsAsync(filter); + return await HandlePartitioned(partitionKey).CountDocumentsAsync(filter, cancellationToken: cancellationToken); } /// @@ -188,14 +201,15 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. - public async virtual Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { return await GetCollection(partitionKey).Find(Builders.Filter.Where(filter)) .SortByDescending(maxValueSelector) .Limit(1) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -224,14 +238,15 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partitionKey. - public async virtual Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { return await GetCollection(partitionKey).Find(Builders.Filter.Where(filter)) .SortBy(minValueSelector) .Limit(1) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -257,16 +272,18 @@ namespace MongoDbGenericRepository.DataAccess.Read /// /// The document type. /// The type of the primary key. + /// The type of the field for which you want the maximum value. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector to order by ascending. /// An optional partitionKey. - public async virtual Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { return await GetMaxMongoQuery(filter, maxValueSelector, partitionKey) .Project(maxValueSelector) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -296,11 +313,12 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - public virtual async Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await GetMinMongoQuery(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(); + return await GetMinMongoQuery(filter, minValueSelector, partitionKey).Project(minValueSelector).FirstOrDefaultAsync(cancellationToken); } /// @@ -332,13 +350,15 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. + /// An optional cancellation Token. public virtual async Task SumByAsync(Expression> filter, Expression> selector, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await GetQuery(filter, partitionKey).SumAsync(selector); + return await GetQuery(filter, partitionKey).SumAsync(selector, cancellationToken); } /// @@ -366,13 +386,14 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. + /// An optional cancellation Token. public virtual async Task SumByAsync(Expression> filter, Expression> selector, - string partitionKey = null) + string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await GetQuery(filter, partitionKey).SumAsync(selector); + return await GetQuery(filter, partitionKey).SumAsync(selector, cancellationToken); } /// @@ -451,6 +472,36 @@ namespace MongoDbGenericRepository.DataAccess.Read .ToList(); } + /// + /// Groups filtered a collection of documents given a grouping criteria, + /// and returns a dictionary of listed document groups with keys having the different values of the grouping criteria. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type of the grouping criteria. + /// The type of the projected group. + /// A LINQ expression filter. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + /// An optional cancellation Token. + public virtual async Task> GroupByAsync( + Expression> filter, + Expression> selector, + Expression, TProjection>> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new() + { + var collection = HandlePartitioned(partitionKey); + return await collection.Aggregate() + .Match(Builders.Filter.Where(filter)) + .Group(selector, projection) + .ToListAsync(cancellationToken); + } + /// /// Asynchronously returns a paginated list of the documents matching the filter condition. /// @@ -462,13 +513,15 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation Token. public virtual async Task> GetSortedPaginatedAsync( Expression> filter, Expression> sortSelector, bool ascending = true, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -481,7 +534,7 @@ namespace MongoDbGenericRepository.DataAccess.Read .Sort(sorting) .Skip(skipNumber) .Limit(takeNumber) - .ToListAsync(); + .ToListAsync(cancellationToken); } /// @@ -494,12 +547,14 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation Token. public virtual async Task> GetSortedPaginatedAsync( Expression> filter, SortDefinition sortDefinition, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -508,7 +563,7 @@ namespace MongoDbGenericRepository.DataAccess.Read .Sort(sortDefinition) .Skip(skipNumber) .Limit(takeNumber) - .ToListAsync(); + .ToListAsync(cancellationToken); } } } diff --git a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs index 3499a66..378e86e 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs @@ -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.DataAccess.Read @@ -20,14 +21,19 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - public virtual async Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class { return await HandlePartitioned(partitionKey).Find(filter) .Project(projection) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(cancellationToken); } /// @@ -58,14 +64,19 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - public virtual async Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class { return await HandlePartitioned(partitionKey).Find(filter) .Project(projection) - .ToListAsync(); + .ToListAsync(cancellationToken); } /// diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs index c445c2f..98131fd 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs @@ -2,6 +2,7 @@ using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -18,7 +19,8 @@ namespace MongoDbGenericRepository /// /// The type representing a Document. /// The document you want to add. - Task AddOneAsync(TDocument document) where TDocument : IDocument; + /// An optional cancellation Token. + Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument; /// /// Adds a document to the collection. @@ -34,7 +36,8 @@ namespace MongoDbGenericRepository /// /// The type representing a Document. /// The documents you want to add. - Task AddManyAsync(IEnumerable documents) where TDocument : IDocument; + /// An optional cancellation Token. + Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument; /// /// Adds a list of documents to the collection. @@ -81,9 +84,10 @@ namespace MongoDbGenericRepository /// /// The type representing a Document. /// The document you want to add. - public virtual async Task AddOneAsync(TDocument document) where TDocument : IDocument + /// An optional cancellation Token. + public virtual async Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument { - await MongoDbCreator.AddOneAsync(document); + await MongoDbCreator.AddOneAsync(document, cancellationToken); } /// @@ -103,9 +107,10 @@ namespace MongoDbGenericRepository /// /// The type representing a Document. /// The documents you want to add. - public virtual async Task AddManyAsync(IEnumerable documents) where TDocument : IDocument + /// An optional cancellation Token. + public virtual async Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument { - await MongoDbCreator.AddManyAsync(documents); + await MongoDbCreator.AddManyAsync(documents, cancellationToken); } /// diff --git a/MongoDbGenericRepository/Models/IndexCreationOptions.cs b/MongoDbGenericRepository/Models/IndexCreationOptions.cs index a117b2a..ad2d60c 100644 --- a/MongoDbGenericRepository/Models/IndexCreationOptions.cs +++ b/MongoDbGenericRepository/Models/IndexCreationOptions.cs @@ -52,10 +52,6 @@ namespace MongoDbGenericRepository.Models /// public string DefaultLanguage { get; set; } /// - /// Gets or sets the size of a geohash bucket. - /// - public double? BucketSize { get; set; } - /// /// Gets or sets the precision, in bits, used with geohash indexes. /// public int? Bits { get; set; } diff --git a/MongoDbGenericRepository/MongoDbGenericRepository.csproj b/MongoDbGenericRepository/MongoDbGenericRepository.csproj index f569520..c22899f 100644 --- a/MongoDbGenericRepository/MongoDbGenericRepository.csproj +++ b/MongoDbGenericRepository/MongoDbGenericRepository.csproj @@ -2,8 +2,9 @@ net452;netstandard2.0;netstandard1.5; + true MongoDbGenericRepository - 1.4.5 + 1.4.6 Alexandre Spieser MongoDb Generic Repository A generic repository implementation using the MongoDB C# Sharp 2.0 driver. @@ -11,28 +12,20 @@ http://www.opensource.org/licenses/mit-license.php false Release notes are at https://github.com/alexandre-spieser/mongodb-generic-repository/releases - Copyright 2020 (c) Alexandre Spieser. All rights reserved. + Copyright 2021 (c) Alexandre Spieser. All rights reserved. MongoDb Repository Generic NoSql true - 1.4.5 + 1.4.6 https://github.com/alexandre-spieser/mongodb-generic-repository Git - - bin\Release\net45\MongoDbGenericRepository.xml - - - - - - - - D:\development\mongodb-generic-repository\MongoDbGenericRepository\MongoDbGenericRepository.xml - + + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + - + diff --git a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs index e9ed276..9c9e33e 100644 --- a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs +++ b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs @@ -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 /// The type of the primary key for a Document. /// The Id of the document you want to get. /// An optional partition key. - public async virtual Task GetByIdAsync(TKey id, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetByIdAsync(id, partitionKey); + return await MongoDbReader.GetByIdAsync(id, partitionKey, cancellationToken); } /// @@ -77,11 +79,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetOneAsync(filter, partitionKey); + return await MongoDbReader.GetOneAsync(filter, partitionKey, cancellationToken); } /// @@ -119,11 +122,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task AnyAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.AnyAsync(filter, partitionKey); + return await MongoDbReader.AnyAsync(filter, partitionKey, cancellationToken); } /// @@ -147,11 +151,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partition key. - public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetAllAsync(filter, partitionKey); + return await MongoDbReader.GetAllAsync(filter, partitionKey, cancellationToken); } /// @@ -175,11 +180,12 @@ namespace MongoDbGenericRepository /// The type of the primary key for a Document. /// A LINQ expression filter. /// An optional partitionKey - public async virtual Task CountAsync(Expression> filter, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.CountAsync(filter, partitionKey); + return await MongoDbReader.CountAsync(filter, partitionKey, cancellationToken); } /// @@ -204,11 +210,15 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// A property selector to order by descending. /// An optional partitionKey. - public async virtual Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByMaxAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey); + return await MongoDbReader.GetByMaxAsync(filter, maxValueSelector, partitionKey, cancellationToken); } /// @@ -232,13 +242,17 @@ namespace MongoDbGenericRepository /// The document type. /// The type of the primary key. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector for the minimum value you are looking for. /// An optional partitionKey. - public async virtual Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetByMinAsync(Expression> filter, + Expression> minValueSelector, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetByMinAsync(filter, minValueSelector, partitionKey); + return await MongoDbReader.GetByMinAsync(filter, minValueSelector, partitionKey, cancellationToken); } /// @@ -247,7 +261,7 @@ namespace MongoDbGenericRepository /// The document type. /// The type of the primary key. /// A LINQ expression filter. - /// A property selector to order by ascending. + /// A property selector for the minimum value you are looking for. /// An optional partitionKey. public virtual TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) where TDocument : IDocument @@ -263,13 +277,18 @@ namespace MongoDbGenericRepository /// The type of the primary key. /// The type of the value used to order the query. /// A LINQ expression filter. - /// A property selector to select the max value. + /// A property selector for the maximum value you are looking for. /// An optional partitionKey. - public async virtual Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public async virtual Task GetMaxValueAsync( + Expression> filter, + Expression> maxValueSelector, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey); + return await MongoDbReader.GetMaxValueAsync(filter, maxValueSelector, partitionKey, cancellationToken); } /// @@ -297,11 +316,16 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// A property selector to order by ascending. /// An optional partition key. - public virtual async Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task GetMinValueAsync( + Expression> filter, + Expression> minValueSelector, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey); + return await MongoDbReader.GetMinValueAsync(filter, minValueSelector, partitionKey, cancellationToken); } /// @@ -332,13 +356,15 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// The field you want to sum. /// The partition key of your document, if any. + /// An optional cancellation Token. public virtual async Task SumByAsync(Expression> filter, Expression> selector, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { - return await MongoDbReader.SumByAsync(filter, selector, partitionKey); + return await MongoDbReader.SumByAsync(filter, selector, partitionKey, cancellationToken); } /// @@ -405,12 +431,17 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - public virtual async Task ProjectOneAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task ProjectOneAsync( + Expression> filter, + Expression> projection, + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class { - return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey); + return await MongoDbReader.ProjectOneAsync(filter, projection, partitionKey, cancellationToken); } /// @@ -439,12 +470,16 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// The projection expression. /// An optional partition key. - public virtual async Task> ProjectManyAsync(Expression> filter, Expression> projection, string partitionKey = null) + /// An optional cancellation Token. + public virtual async Task> ProjectManyAsync( + Expression> filter, + Expression> projection, + string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable where TProjection : class { - return await MongoDbReader.ProjectManyAsync(filter, projection, partitionKey); + return await MongoDbReader.ProjectManyAsync(filter, projection, partitionKey, cancellationToken); } /// @@ -562,12 +597,14 @@ namespace MongoDbGenericRepository /// The number of documents you want to skip. Default value is 0. /// The number of documents you want to take. Default value is 50. /// An optional partition key. + /// An optional cancellation Token. public virtual async Task> GetSortedPaginatedAsync( Expression> filter, SortDefinition sortDefinition, int skipNumber = 0, int takeNumber = 50, - string partitionKey = null) + string partitionKey = null, + CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -576,7 +613,7 @@ namespace MongoDbGenericRepository .Sort(sortDefinition) .Skip(skipNumber) .Limit(takeNumber) - .ToListAsync(); + .ToListAsync(cancellationToken); } #endregion Pagination