From 02b9385fd8c182e2524b5e0b4613d02e5522fd11 Mon Sep 17 00:00:00 2001 From: Sean Garrett Date: Sun, 11 Jun 2023 20:23:44 +0100 Subject: [PATCH] fixed various warnings --- .../BaseMongoDbRepositoryTests.cs | 6 +- .../Infrastructure/MongoDbConfig.cs | 4 +- .../MongoDbDocumentTestBase.Main.cs | 100 +++++----- .../Abstractions/IMongoDbContext.cs | 2 - .../IReadOnlyMongoRepository.TKey.cs | 5 +- .../BaseMongoRepository.Delete.cs | 3 + .../BaseMongoRepository.Index.cs | 19 +- .../BaseMongoRepository.Update.cs | 4 +- .../DataAccess/Base/DataAccessBase.cs | 1 - .../DataAccess/Base/IDataAccessBase.cs | 3 + .../DataAccess/Create/IMongoDbCreator.cs | 51 +---- .../DataAccess/Create/MongoDbCreator.cs | 32 ++-- .../DataAccess/Delete/IMongoDbEraser.cs | 50 +---- .../DataAccess/Delete/MongoDbEraser.cs | 48 +++-- .../DataAccess/Index/IMongoDbIndexHandler.cs | 50 +---- .../DataAccess/Index/MongoDbIndexHandler.cs | 20 +- .../DataAccess/Read/IMongoDbReader.cs | 49 +---- .../DataAccess/Read/MongoDbReader.Main.cs | 16 +- .../DataAccess/Update/IMongoDbUpdater.cs | 58 +----- .../Update/MongoDbUpdater.ClientSession.cs | 124 +----------- .../DataAccess/Update/MongoDbUpdater.cs | 180 +++--------------- .../IBaseMongoRepository.Delete.cs | 3 + .../IBaseMongoRepository.Index.cs | 3 + .../BaseMongoRepository.TKey.Create.cs | 8 +- .../BaseMongoRepository.TKey.Index.cs | 14 +- .../BaseMongoRepository.TKey.ReadOnly.cs | 19 +- .../BaseMongoRepository.TKey.Update.cs | 3 + .../IBaseMongoRepository.TKey.Update.cs | 4 + .../Models/IndexCreationOptions.cs | 4 - .../ReadOnlyMongoRepository.cs | 17 +- 30 files changed, 245 insertions(+), 655 deletions(-) diff --git a/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs b/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs index 22b5423..7d00f01 100644 --- a/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs +++ b/CoreIntegrationTests/Infrastructure/BaseMongoDbRepositoryTests.cs @@ -62,18 +62,18 @@ namespace CoreIntegrationTests.Infrastructure } #region IDisposable Support - private bool disposedValue = false; // Pour détecter les appels redondants + private bool _disposedValue; // Pour détecter les appels redondants protected virtual void Dispose(bool disposing) { - if (!disposedValue) + if (!_disposedValue) { if (disposing) { Cleanup(); } - disposedValue = true; + _disposedValue = true; } } diff --git a/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs b/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs index eb87022..c41302a 100644 --- a/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs +++ b/CoreIntegrationTests/Infrastructure/MongoDbConfig.cs @@ -5,8 +5,8 @@ namespace CoreIntegrationTests.Infrastructure { internal static class MongoDbConfig { - private static bool _initialized = false; - private static object _initializationLock = new object(); + private static bool _initialized; + private static object _initializationLock = new(); private static object _initializationTarget; public static void EnsureConfigured() diff --git a/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs b/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs index 98fc846..893908c 100644 --- a/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs +++ b/CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs @@ -1,6 +1,4 @@ -using MongoDbGenericRepository; -using MongoDbGenericRepository.Models; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -8,12 +6,12 @@ using System.Linq.Expressions; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; +using MongoDbGenericRepository.Models; using Xunit; namespace CoreIntegrationTests.Infrastructure { - public abstract partial class MongoDbDocumentTestBase : - IClassFixture> + public abstract partial class MongoDbDocumentTestBase where T : TestDoc, new() { @@ -74,7 +72,7 @@ namespace CoreIntegrationTests.Infrastructure // Arrange var document = CreateTestDocument(); // Act - SUT.AddOne(document); + SUT.AddOne(document); // Assert long count = string.IsNullOrEmpty(PartitionKey) ? SUT.Count(e => e.Id.Equals(document.Id)) : SUT.Count(e => e.Id.Equals(document.Id), PartitionKey); @@ -87,7 +85,7 @@ namespace CoreIntegrationTests.Infrastructure // Arrange var document = CreateTestDocument(); // Act - await SUT.AddOneAsync(document); + await SUT.AddOneAsync(document); // Assert long count = string.IsNullOrEmpty(PartitionKey) ? SUT.Count(e => e.Id.Equals(document.Id)) : SUT.Count(e => e.Id.Equals(document.Id), PartitionKey); @@ -100,7 +98,7 @@ namespace CoreIntegrationTests.Infrastructure // Arrange var documents = CreateTestDocuments(2); // Act - SUT.AddMany(documents); + SUT.AddMany(documents); // Assert long count = string.IsNullOrEmpty(PartitionKey) ? SUT.Count(e => e.Id.Equals(documents[0].Id) || e.Id.Equals(documents[1].Id)) @@ -123,7 +121,7 @@ namespace CoreIntegrationTests.Infrastructure ((IPartitionedDocument)documents[2]).PartitionKey = secondPartitionKey; ((IPartitionedDocument)documents[3]).PartitionKey = secondPartitionKey; // Act - SUT.AddMany(documents); + SUT.AddMany(documents); // Assert long count = SUT.Count(e => e.Id.Equals(documents[0].Id) || e.Id.Equals(documents[1].Id), PartitionKey); long secondPartitionCount = SUT.Count(e => e.Id.Equals(documents[2].Id) || e.Id.Equals(documents[3].Id), secondPartitionKey); @@ -141,7 +139,7 @@ namespace CoreIntegrationTests.Infrastructure // Arrange var documents = CreateTestDocuments(2); // Act - await SUT.AddManyAsync(documents); + await SUT.AddManyAsync(documents); // Assert long count = string.IsNullOrEmpty(PartitionKey) ? SUT.Count(e => e.Id.Equals(documents[0].Id) || e.Id.Equals(documents[1].Id)) @@ -164,7 +162,7 @@ namespace CoreIntegrationTests.Infrastructure ((IPartitionedDocument)documents[2]).PartitionKey = secondPartitionKey; ((IPartitionedDocument)documents[3]).PartitionKey = secondPartitionKey; // Act - await SUT.AddManyAsync(documents); + await SUT.AddManyAsync(documents); // Assert long count = SUT.Count(e => e.Id.Equals(documents[0].Id) || e.Id.Equals(documents[1].Id), PartitionKey); long secondPartitionCount = SUT.Count(e => e.Id.Equals(documents[2].Id) || e.Id.Equals(documents[3].Id), secondPartitionKey); @@ -185,7 +183,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + await SUT.AddOneAsync(document); // Act var result = await SUT.GetByIdAsync(document.Id, PartitionKey); // Assert @@ -197,7 +195,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = SUT.GetById(document.Id, PartitionKey); // Assert @@ -209,7 +207,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = await SUT.GetOneAsync(x => x.Id.Equals(document.Id), PartitionKey); // Assert @@ -221,7 +219,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = SUT.GetOne(x => x.Id.Equals(document.Id), PartitionKey); // Assert @@ -233,7 +231,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var cursor = SUT.GetCursor(x => x.Id.Equals(document.Id), PartitionKey); var count = cursor.CountDocuments(); @@ -246,7 +244,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = await SUT.AnyAsync(x => x.Id.Equals(document.Id), PartitionKey); // Assert @@ -258,7 +256,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = await SUT.AnyAsync(x => x.Id.Equals(Guid.NewGuid()), PartitionKey); // Assert @@ -270,7 +268,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = SUT.Any(x => x.Id.Equals(document.Id), PartitionKey); // Assert @@ -282,7 +280,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = SUT.Any(x => x.Id.Equals(Guid.NewGuid()), PartitionKey); // Assert @@ -296,7 +294,7 @@ namespace CoreIntegrationTests.Infrastructure var documents = CreateTestDocuments(5); var content = GetContent(); documents.ForEach(e => e.SomeContent = content); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = await SUT.GetAllAsync(x => x.SomeContent == content, PartitionKey); // Assert @@ -310,7 +308,7 @@ namespace CoreIntegrationTests.Infrastructure var documents = CreateTestDocuments(5); var content = GetContent(); documents.ForEach(e => e.SomeContent = content); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = SUT.GetAll(x => x.SomeContent == content, PartitionKey); // Assert @@ -324,7 +322,7 @@ namespace CoreIntegrationTests.Infrastructure var documents = CreateTestDocuments(5); var content = GetContent(); documents.ForEach(e => e.SomeContent = content); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = await SUT.CountAsync(x => x.SomeContent == content, PartitionKey); // Assert @@ -338,7 +336,7 @@ namespace CoreIntegrationTests.Infrastructure var documents = CreateTestDocuments(5); var content = GetContent(); documents.ForEach(e => e.SomeContent = content); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = SUT.Count(x => x.SomeContent == content, PartitionKey); // Assert @@ -354,9 +352,9 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act - var result = SUT.DeleteOne(document); + var result = SUT.DeleteOne(document); // Assert Assert.True(1 == result); Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); @@ -367,7 +365,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = SUT.DeleteOne(e => e.Id.Equals(document.Id), PartitionKey); // Assert @@ -380,9 +378,9 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act - var result = await SUT.DeleteOneAsync(document); + var result = await SUT.DeleteOneAsync(document); // Assert Assert.True(1 == result); Assert.False(SUT.Any(e => e.Id.Equals(document.Id), PartitionKey), GetTestName()); @@ -393,7 +391,7 @@ namespace CoreIntegrationTests.Infrastructure { // Arrange var document = CreateTestDocument(); - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = await SUT.DeleteOneAsync(e => e.Id.Equals(document.Id), PartitionKey); // Assert @@ -408,7 +406,7 @@ namespace CoreIntegrationTests.Infrastructure var criteria = $"{GetTestName()}.{DocumentTypeName}"; var documents = CreateTestDocuments(5); documents.ForEach(e => e.SomeContent = criteria); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = await SUT.DeleteManyAsync(e => e.SomeContent == criteria, PartitionKey); // Assert @@ -432,9 +430,9 @@ namespace CoreIntegrationTests.Infrastructure ((IPartitionedDocument)documents[4]).PartitionKey = secondKey; } - SUT.AddMany(documents); + SUT.AddMany(documents); // Act - var result = await SUT.DeleteManyAsync(documents); + var result = await SUT.DeleteManyAsync(documents); // Assert Assert.True(5 == result); Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); @@ -451,7 +449,7 @@ namespace CoreIntegrationTests.Infrastructure var criteria = $"{GetTestName()}.{DocumentTypeName}"; var documents = CreateTestDocuments(5); documents.ForEach(e => e.SomeContent = criteria); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = SUT.DeleteMany(e => e.SomeContent == criteria, PartitionKey); // Assert @@ -475,9 +473,9 @@ namespace CoreIntegrationTests.Infrastructure ((IPartitionedDocument)documents[4]).PartitionKey = secondKey; } - SUT.AddMany(documents); + SUT.AddMany(documents); // Act - var result = SUT.DeleteMany(documents); + var result = SUT.DeleteMany(documents); // Assert Assert.True(5 == result); Assert.False(SUT.Any(e => e.SomeContent == criteria, PartitionKey), GetTestName()); @@ -500,7 +498,7 @@ namespace CoreIntegrationTests.Infrastructure var document = CreateTestDocument(); document.SomeContent = someContent; document.Nested.SomeDate = someDate; - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = await SUT.ProjectOneAsync( x => x.Id.Equals(document.Id), @@ -526,7 +524,7 @@ namespace CoreIntegrationTests.Infrastructure var document = CreateTestDocument(); document.SomeContent = someContent; document.Nested.SomeDate = someDate; - SUT.AddOne(document); + SUT.AddOne(document); // Act var result = SUT.ProjectOne( x => x.Id.Equals(document.Id), @@ -556,7 +554,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = someDate; }); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = await SUT.ProjectManyAsync( x => x.SomeContent == someContent, @@ -586,7 +584,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = someDate; }); - SUT.AddMany(documents); + SUT.AddMany(documents); // Act var result = SUT.ProjectMany( x => x.SomeContent == someContent, @@ -619,7 +617,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); // Act @@ -642,7 +640,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); // Act @@ -665,7 +663,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); // Act @@ -688,7 +686,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); // Act @@ -711,7 +709,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); // Act @@ -734,7 +732,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMin = documents.OrderBy(e => e.Nested.SomeDate).First(); // Act @@ -757,7 +755,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMax = documents.OrderByDescending(e => e.Nested.SomeDate).First(); // Act @@ -780,7 +778,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeDate = e.Nested.SomeDate.AddDays(i++); e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedMin = documents.OrderByDescending(e => e.Nested.SomeDate).First(); // Act @@ -910,7 +908,7 @@ namespace CoreIntegrationTests.Infrastructure // Act Expression > ex = x => x.SomeContent2; Expression > ex2 = x => x.SomeContent3; - var result = await SUT.CreateCombinedTextIndexAsync(new[] { ex, ex2 }, null, PartitionKey); + var result = await SUT.CreateCombinedTextIndexAsync(new[] { ex, ex2 }, null, PartitionKey); // Assert var listOfIndexNames = await SUT.GetIndexesNamesAsync(PartitionKey); @@ -937,7 +935,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeAmount = 5m; e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedSum = documents.Sum(e => e.Nested.SomeAmount); // Act @@ -960,7 +958,7 @@ namespace CoreIntegrationTests.Infrastructure e.Nested.SomeAmount = 5m; e.SomeContent = criteria; }); - SUT.AddMany(documents); + SUT.AddMany(documents); var expectedSum = documents.Sum(e => e.Nested.SomeAmount); // Act diff --git a/MongoDbGenericRepository/Abstractions/IMongoDbContext.cs b/MongoDbGenericRepository/Abstractions/IMongoDbContext.cs index 2a05c8d..bca34b4 100644 --- a/MongoDbGenericRepository/Abstractions/IMongoDbContext.cs +++ b/MongoDbGenericRepository/Abstractions/IMongoDbContext.cs @@ -1,6 +1,4 @@ using MongoDB.Driver; -using MongoDbGenericRepository.Models; -using System; namespace MongoDbGenericRepository { diff --git a/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs b/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs index a61374c..4290a2b 100644 --- a/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs +++ b/MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs @@ -2,13 +2,16 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { + /// + /// read only repository interface + /// + /// The key type public interface IReadOnlyMongoRepository where TKey : IEquatable { #region Read diff --git a/MongoDbGenericRepository/BaseMongoRepository.Delete.cs b/MongoDbGenericRepository/BaseMongoRepository.Delete.cs index cba59a8..a5e8748 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Delete.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Delete.cs @@ -11,6 +11,9 @@ namespace MongoDbGenericRepository { private volatile IMongoDbEraser _mongoDbEraser; + /// + /// The MongoDbEraser used to delete documents. + /// protected virtual IMongoDbEraser MongoDbEraser { get diff --git a/MongoDbGenericRepository/BaseMongoRepository.Index.cs b/MongoDbGenericRepository/BaseMongoRepository.Index.cs index f74972a..f77af83 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Index.cs @@ -15,6 +15,9 @@ namespace MongoDbGenericRepository { private volatile IMongoDbIndexHandler _mongoDbIndexHandler; + /// + /// The MongoDb accessor to manage indexes. + /// protected virtual IMongoDbIndexHandler MongoDbIndexHandler { get @@ -37,7 +40,6 @@ namespace MongoDbGenericRepository /// Returns the names of the indexes present on a collection. /// /// The type representing a Document. - /// The type of the primary key for a Document. /// An optional partition key /// A list containing the names of the indexes on on the concerned collection. public async Task> GetIndexesNamesAsync(string partitionKey = null) @@ -50,9 +52,10 @@ namespace MongoDbGenericRepository /// Returns the names of the indexes present on a collection. /// /// The type representing a Document. + /// The type for the key of the document. /// An optional partition key /// A list containing the names of the indexes on on the concerned collection. - public async virtual Task> GetIndexesNamesAsync(string partitionKey = null) + public virtual async Task> GetIndexesNamesAsync(string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -86,7 +89,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -120,7 +123,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -144,7 +147,7 @@ namespace MongoDbGenericRepository } /// - public async virtual Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -168,7 +171,7 @@ namespace MongoDbGenericRepository } /// - public async virtual Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -192,7 +195,7 @@ namespace MongoDbGenericRepository } /// - public async virtual Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -212,7 +215,7 @@ namespace MongoDbGenericRepository } /// - public async virtual Task DropIndexAsync(string indexName, string partitionKey = null) + public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { diff --git a/MongoDbGenericRepository/BaseMongoRepository.Update.cs b/MongoDbGenericRepository/BaseMongoRepository.Update.cs index c4272f5..7bc1497 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Update.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Update.cs @@ -15,6 +15,9 @@ namespace MongoDbGenericRepository { private volatile IMongoDbUpdater _mongoDbUpdater; + /// + /// The MongoDb accessor to update data. + /// protected virtual IMongoDbUpdater MongoDbUpdater { get @@ -203,7 +206,6 @@ namespace MongoDbGenericRepository /// For the entities selected by the filter, applies the update you have defined in MongoDb. /// /// The type representing a Document. - /// The type of the primary key for a Document. /// The document filter. /// The update definition to apply. /// The value of the partition key. diff --git a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs index a59d0b4..1875161 100644 --- a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs +++ b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs @@ -2,7 +2,6 @@ using MongoDB.Driver.Linq; using MongoDbGenericRepository.Models; using System; -using System.Linq; using System.Linq.Expressions; namespace MongoDbGenericRepository.DataAccess.Base diff --git a/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs index b81ea09..af0fb43 100644 --- a/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs +++ b/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs @@ -6,6 +6,9 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Base { + /// + /// A interface for accessing the Database and its Collections. + /// public interface IDataAccessBase { /// diff --git a/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs b/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs index 018b8c4..00b299e 100644 --- a/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs +++ b/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs @@ -1,15 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; -using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Create { + /// + /// A interface for adding documents to the Database and its Collections. + /// public interface IMongoDbCreator : IDataAccessBase { /// @@ -57,50 +57,5 @@ namespace MongoDbGenericRepository.DataAccess.Create void AddMany(IEnumerable documents) where TDocument : IDocument where TKey : IEquatable; - - /// - /// 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. - /// - IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The document. - /// - IMongoCollection HandlePartitioned(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection HandlePartitioned(string partitionKey) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for the type TDocument with a partition key. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection GetCollection(string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; } } \ No newline at end of file diff --git a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs index de95085..30f8693 100644 --- a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs +++ b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs @@ -1,6 +1,4 @@ -using MongoDB.Driver; -using MongoDB.Driver.Linq; -using MongoDbGenericRepository.DataAccess.Base; +using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; using MongoDbGenericRepository.Utils; using System; @@ -69,25 +67,29 @@ namespace MongoDbGenericRepository.DataAccess.Create where TDocument : IDocument where TKey : IEquatable { - if (!documents.Any()) + var documentsList = documents.ToList(); + + if (!documentsList.Any()) { return; } - foreach (var document in documents) + + foreach (var document in documentsList) { FormatDocument(document); } + // cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5 - if (documents.Any(e => e is IPartitionedDocument)) + if (documentsList.Any(e => e is IPartitionedDocument)) { - foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) + foreach (var group in documentsList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) { await HandlePartitioned(group.FirstOrDefault()).InsertManyAsync(group.ToList(), null, cancellationToken); } } else { - await GetCollection().InsertManyAsync(documents.ToList(), null, cancellationToken); + await GetCollection().InsertManyAsync(documentsList.ToList(), null, cancellationToken); } } @@ -102,25 +104,29 @@ namespace MongoDbGenericRepository.DataAccess.Create where TDocument : IDocument where TKey : IEquatable { - if (!documents.Any()) + var documentList = documents.ToList(); + + if (!documentList.Any()) { return; } - foreach (var document in documents) + + foreach (var document in documentList) { FormatDocument(document); } + // cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5 - if (documents.Any(e => e is IPartitionedDocument)) + if (documentList.Any(e => e is IPartitionedDocument)) { - foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) + foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) { HandlePartitioned(group.FirstOrDefault()).InsertMany(group.ToList()); } } else { - GetCollection().InsertMany(documents.ToList()); + GetCollection().InsertMany(documentList.ToList()); } } diff --git a/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs b/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs index 43eec28..61a3d9d 100644 --- a/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs +++ b/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs @@ -2,13 +2,14 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; -using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Delete { + /// + /// The MongoDbEraser interface. used to delete documents from the collections. + /// public interface IMongoDbEraser : IDataAccessBase { /// @@ -102,50 +103,5 @@ namespace MongoDbGenericRepository.DataAccess.Delete long DeleteMany(Expression> filter, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; - - /// - /// 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. - /// - IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The document. - /// - IMongoCollection HandlePartitioned(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection HandlePartitioned(string partitionKey) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for the type TDocument with a partition key. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection GetCollection(string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; } } \ No newline at end of file diff --git a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs index b28d027..5cf6486 100644 --- a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs +++ b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs @@ -1,5 +1,4 @@ using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; using System; @@ -10,8 +9,13 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Delete { + /// public class MongoDbEraser : DataAccessBase, IMongoDbEraser { + /// + /// The MongoDbEraser constructor. + /// + /// the MongoDb Context public MongoDbEraser(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } @@ -104,26 +108,27 @@ namespace MongoDbGenericRepository.DataAccess.Delete where TDocument : IDocument where TKey : IEquatable { - if (!documents.Any()) + var documentList = documents.ToList(); + + if (!documentList.Any()) { return 0; } + // cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5 - if (documents.Any(e => e is IPartitionedDocument)) + if (documentList.Any(e => e is IPartitionedDocument)) { long deleteCount = 0; - foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) + foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) { - var groupIdsTodelete = group.Select(e => e.Id).ToArray(); - deleteCount += (await HandlePartitioned(group.FirstOrDefault()).DeleteManyAsync(x => groupIdsTodelete.Contains(x.Id))).DeletedCount; + var groupIdsToDelete = group.Select(e => e.Id).ToArray(); + deleteCount += (await HandlePartitioned(group.FirstOrDefault()).DeleteManyAsync(x => groupIdsToDelete.Contains(x.Id))).DeletedCount; } return deleteCount; } - else - { - var idsTodelete = documents.Select(e => e.Id).ToArray(); - return (await HandlePartitioned(documents.FirstOrDefault()).DeleteManyAsync(x => idsTodelete.Contains(x.Id))).DeletedCount; - } + + var idsToDelete = documentList.Select(e => e.Id).ToArray(); + return (await HandlePartitioned(documentList.FirstOrDefault()).DeleteManyAsync(x => idsToDelete.Contains(x.Id))).DeletedCount; } /// @@ -137,26 +142,27 @@ namespace MongoDbGenericRepository.DataAccess.Delete where TDocument : IDocument where TKey : IEquatable { - if (!documents.Any()) + var documentList = documents.ToList(); + + if (!documentList.Any()) { return 0; } + // cannot use typeof(IPartitionedDocument).IsAssignableFrom(typeof(TDocument)), not available in netstandard 1.5 - if (documents.Any(e => e is IPartitionedDocument)) + if (documentList.Any(e => e is IPartitionedDocument)) { long deleteCount = 0; - foreach (var group in documents.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) + foreach (var group in documentList.GroupBy(e => ((IPartitionedDocument)e).PartitionKey)) { - var groupIdsTodelete = group.Select(e => e.Id).ToArray(); - deleteCount += (HandlePartitioned(group.FirstOrDefault()).DeleteMany(x => groupIdsTodelete.Contains(x.Id))).DeletedCount; + var groupIdsToDelete = group.Select(e => e.Id).ToArray(); + deleteCount += (HandlePartitioned(group.FirstOrDefault()).DeleteMany(x => groupIdsToDelete.Contains(x.Id))).DeletedCount; } return deleteCount; } - else - { - var idsTodelete = documents.Select(e => e.Id).ToArray(); - return (HandlePartitioned(documents.FirstOrDefault()).DeleteMany(x => idsTodelete.Contains(x.Id))).DeletedCount; - } + + var idsToDelete = documentList.Select(e => e.Id).ToArray(); + return HandlePartitioned(documentList.FirstOrDefault()).DeleteMany(x => idsToDelete.Contains(x.Id)).DeletedCount; } /// diff --git a/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs b/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs index b9b8338..247ad6a 100644 --- a/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs +++ b/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs @@ -2,13 +2,14 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; -using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Index { + /// + /// The MongoDbIndexHandler interface. used to create indexes on collections. + /// public interface IMongoDbIndexHandler : IDataAccessBase { /// @@ -107,50 +108,5 @@ namespace MongoDbGenericRepository.DataAccess.Index Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; - - /// - /// 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. - /// - IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The document. - /// - IMongoCollection HandlePartitioned(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection HandlePartitioned(string partitionKey) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for the type TDocument with a partition key. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection GetCollection(string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; } } \ No newline at end of file diff --git a/MongoDbGenericRepository/DataAccess/Index/MongoDbIndexHandler.cs b/MongoDbGenericRepository/DataAccess/Index/MongoDbIndexHandler.cs index dbf1b9a..a4bf5e8 100644 --- a/MongoDbGenericRepository/DataAccess/Index/MongoDbIndexHandler.cs +++ b/MongoDbGenericRepository/DataAccess/Index/MongoDbIndexHandler.cs @@ -1,5 +1,4 @@ using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; using System; @@ -10,8 +9,13 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Index { + /// public class MongoDbIndexHandler : DataAccessBase, IMongoDbIndexHandler { + /// + /// The MongoDbIndexHandler constructor. + /// + /// The mongo db context public MongoDbIndexHandler(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } @@ -23,7 +27,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// The type of the primary key for a Document. /// An optional partition key /// A list containing the names of the indexes on on the concerned collection. - public async virtual Task> GetIndexesNamesAsync(string partitionKey = null) + public virtual async Task> GetIndexesNamesAsync(string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -43,7 +47,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -66,7 +70,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -89,7 +93,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -112,7 +116,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -135,7 +139,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { @@ -157,7 +161,7 @@ namespace MongoDbGenericRepository.DataAccess.Index /// The type of the primary key for a Document. /// The name of the index /// An optional partition key - public async virtual Task DropIndexAsync(string indexName, string partitionKey = null) + public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { diff --git a/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs b/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs index f3c6e38..8665bd8 100644 --- a/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs +++ b/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs @@ -5,12 +5,14 @@ using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Read { + /// + /// A interface for accessing the Database and its Collections. + /// public interface IMongoDbReader : IDataAccessBase { /// @@ -582,50 +584,5 @@ namespace MongoDbGenericRepository.DataAccess.Read string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; - - /// - /// 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. - /// - IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The document. - /// - IMongoCollection HandlePartitioned(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection HandlePartitioned(string partitionKey) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for the type TDocument with a partition key. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection GetCollection(string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; } } \ No newline at end of file diff --git a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs index c343668..7252cc4 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Main.cs @@ -34,7 +34,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// The Id of the document you want to get. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -98,7 +98,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -176,7 +176,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -240,7 +240,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -302,7 +302,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A LINQ expression filter. /// An optional partitionKey /// An optional cancellation Token. - public async virtual Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -336,7 +336,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A property selector to order by descending. /// An optional partitionKey. /// An optional cancellation Token. - public async virtual Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -373,7 +373,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A property selector to order by ascending. /// An optional partitionKey. /// An optional cancellation Token. - public async virtual Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -411,7 +411,7 @@ namespace MongoDbGenericRepository.DataAccess.Read /// A property selector to order by ascending. /// An optional partitionKey. /// An optional cancellation Token. - public async virtual Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { diff --git a/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs b/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs index 7550d16..abc8124 100644 --- a/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs +++ b/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs @@ -3,12 +3,14 @@ using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; -using MongoDB.Driver.Linq; using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository.DataAccess.Update { + /// + /// A interface for updating documents in MongoDb. + /// public interface IMongoDbUpdater : IDataAccessBase { /// @@ -323,8 +325,7 @@ namespace MongoDbGenericRepository.DataAccess.Update /// The type representing a Document. /// The type of the primary key for a Document. /// The document filter. - /// The field selector. - /// The new value of the property field. + /// the update definiton /// The value of the partition key. Task UpdateManyAsync(Expression> filter, UpdateDefinition update, string partitionKey = null) where TDocument : IDocument @@ -335,7 +336,6 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field. /// The document filter. /// The update definition. /// The value of the partition key. @@ -376,56 +376,10 @@ namespace MongoDbGenericRepository.DataAccess.Update /// /// The type representing a Document. /// The type of the primary key for a Document. - /// The type of the field. /// The document filter. - /// The update definition. + /// The update definition. /// The value of the partition key. - long UpdateMany(FilterDefinition filter, UpdateDefinition UpdateDefinition, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// 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. - /// - IMongoQueryable GetQuery(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The document. - /// - IMongoCollection HandlePartitioned(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for a potentially partitioned document type. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection HandlePartitioned(string partitionKey) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Gets a collections for the type TDocument with a partition key. - /// - /// The document type. - /// The type of the primary key. - /// The collection partition key. - /// - IMongoCollection GetCollection(string partitionKey = null) + long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable; } diff --git a/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.ClientSession.cs b/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.ClientSession.cs index dbb1283..edc0c5c 100644 --- a/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.ClientSession.cs +++ b/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.ClientSession.cs @@ -9,15 +9,7 @@ namespace MongoDbGenericRepository.DataAccess.Update { public partial class MongoDbUpdater { - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The client session. - /// The document with the modifications you want to persist. - /// The optional cancellation token. - /// + /// public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -29,15 +21,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The client session. - /// The document with the modifications you want to persist. - /// The optional cancellation token. - /// + /// public virtual bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -47,16 +31,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 optional cancellation token. - /// + /// public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -66,16 +41,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 optional cancellation token. - /// + /// public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -85,18 +51,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 field to update. - /// The value of the field. - /// The optional cancellation token. - /// + /// public virtual async Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -109,18 +64,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 field to update. - /// The value of the field. - /// The optional cancellation token. - /// + /// public virtual bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -130,19 +74,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 optional cancellation token. - /// + /// 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 @@ -152,19 +84,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 optional cancellation token. - /// + /// public virtual Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) where TDocument : IDocument where TKey : IEquatable @@ -172,19 +92,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return UpdateOneAsync(session, Builders.Filter.Where(filter), field, value, partitionKey, cancellationToken); } - /// - /// Updates a document. - /// - /// 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 optional cancellation token. - /// + /// 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 @@ -194,19 +102,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// 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 optional cancellation token. - /// + /// 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/Update/MongoDbUpdater.cs b/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs index 8fc8c93..2d59aba 100644 --- a/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs +++ b/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs @@ -3,23 +3,24 @@ using MongoDbGenericRepository.DataAccess.Base; using MongoDbGenericRepository.Models; using System; using System.Linq.Expressions; -using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Update { + /// + /// The MongoDb updater. + /// public partial class MongoDbUpdater : DataAccessBase, IMongoDbUpdater { + /// + /// Constructor + /// + /// public MongoDbUpdater(IMongoDbContext mongoDbContext) : base(mongoDbContext) { } - /// - /// Asynchronously Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document with the modifications you want to persist. + /// public virtual async Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument where TKey : IEquatable @@ -29,12 +30,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document with the modifications you want to persist. + /// public virtual bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument where TKey : IEquatable @@ -44,13 +40,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to modify. - /// The update definition for the document. + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument where TKey : IEquatable @@ -60,13 +50,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to modify. - /// The update definition for the document. + /// public virtual bool UpdateOne(TDocument documentToModify, UpdateDefinition update) where TDocument : IDocument where TKey : IEquatable @@ -76,15 +60,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// public virtual async Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable @@ -94,15 +70,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. + /// public virtual bool UpdateOne(TDocument documentToModify, Expression> field, TField value) where TDocument : IDocument where TKey : IEquatable @@ -112,16 +80,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. + /// public virtual async Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -131,16 +90,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. + /// public virtual async Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -148,16 +98,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return await UpdateOneAsync(Builders.Filter.Where(filter), field, value, partitionKey); } - /// - /// Updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. + /// public virtual bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -167,16 +108,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount == 1; } - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. + /// public virtual bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -184,16 +116,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return UpdateOne(Builders.Filter.Where(filter), field, value, partitionKey); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. + /// public virtual async Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -201,16 +124,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return await UpdateManyAsync(Builders.Filter.Where(filter), field, value, partitionKey); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. + /// public virtual async Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -220,15 +134,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount; } - /// - /// For the entities selected by the filter, apply the update definition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. + /// public virtual async Task UpdateManyAsync(Expression> filter, UpdateDefinition update, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -236,15 +142,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return await UpdateManyAsync(Builders.Filter.Where(filter), update, partitionKey); } - /// - /// For the entities selected by the filter, apply the update definition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The update definition. - /// The value of the partition key. + /// public virtual async Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -254,16 +152,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount; } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The partition key for the document. + /// public virtual long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -271,16 +160,7 @@ namespace MongoDbGenericRepository.DataAccess.Update return UpdateMany(Builders.Filter.Where(filter), field, value, partitionKey); } - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The field selector. - /// The new value of the property field. - /// The value of the partition key. + /// public virtual long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable @@ -290,21 +170,13 @@ namespace MongoDbGenericRepository.DataAccess.Update return updateRes.ModifiedCount; } - /// - /// For the entities selected by the filter, apply the update definition. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The type of the field. - /// The document filter. - /// The update definition. - /// The value of the partition key. - public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition UpdateDefinition, string partitionKey = null) + /// + public virtual long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) where TDocument : IDocument where TKey : IEquatable { var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection() : GetCollection(partitionKey); - var updateRes = collection.UpdateMany(filter, UpdateDefinition); + var updateRes = collection.UpdateMany(filter, updateDefinition); return updateRes.ModifiedCount; } } diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs b/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs index 06b2134..eba3e72 100644 --- a/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs +++ b/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs @@ -6,6 +6,9 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { + /// + /// The base Mongo Repository Delete interface. used to delete documents from the collections. + /// public interface IBaseMongoRepository_Delete : IBaseMongoRepository_Delete { /// diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs index 2b711f4..3db3ecf 100644 --- a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs @@ -6,6 +6,9 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { + /// + /// The interface exposing index management functionality for Guid Keyed repositories. + /// public interface IBaseMongoRepository_Index : IBaseMongoRepository_Index { /// diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs index 3b9c28f..850e1a4 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs @@ -11,7 +11,8 @@ namespace MongoDbGenericRepository /// The base Repository, it is meant to be inherited from by your custom custom MongoRepository implementation. /// Its constructor must be given a connection string and a database name. /// - public abstract partial class BaseMongoRepository : IBaseMongoRepository_Create where TKey : IEquatable + public abstract partial class BaseMongoRepository : IBaseMongoRepository_Create + where TKey : IEquatable { private volatile IMongoDbCreator _mongoDbCreator; @@ -22,11 +23,11 @@ namespace MongoDbGenericRepository { get { - if(_mongoDbCreator == null) + if (_mongoDbCreator == null) { lock (_initLock) { - if(_mongoDbCreator == null) + if (_mongoDbCreator == null) { _mongoDbCreator = new MongoDbCreator(MongoDbContext); } @@ -34,6 +35,7 @@ namespace MongoDbGenericRepository } return _mongoDbCreator; } + set { _mongoDbCreator = value; } } diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs index 7363be5..2e37414 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs @@ -44,7 +44,7 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// An optional partition key /// A list containing the names of the indexes on on the concerned collection. - public async virtual Task> GetIndexesNamesAsync(string partitionKey = null) + public virtual async Task> GetIndexesNamesAsync(string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.GetIndexesNamesAsync(partitionKey); @@ -60,7 +60,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateTextIndexAsync(field, indexCreationOptions, partitionKey); @@ -76,7 +76,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateAscendingIndexAsync(field, indexCreationOptions, partitionKey); @@ -92,7 +92,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateDescendingIndexAsync(field, indexCreationOptions, partitionKey); @@ -108,7 +108,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateHashedIndexAsync(field, indexCreationOptions, partitionKey); @@ -124,7 +124,7 @@ namespace MongoDbGenericRepository /// Options for creating an index. /// An optional partition key. /// The result of the create index operation. - public async virtual Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + public virtual async Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) where TDocument : IDocument { return await MongoDbIndexHandler.CreateCombinedTextIndexAsync(fields, indexCreationOptions, partitionKey); @@ -136,7 +136,7 @@ namespace MongoDbGenericRepository /// The type representing a Document. /// The name of the index /// An optional partition key - public async virtual Task DropIndexAsync(string indexName, string partitionKey = null) + public virtual async Task DropIndexAsync(string indexName, string partitionKey = null) where TDocument : IDocument { await MongoDbIndexHandler.DropIndexAsync(indexName, partitionKey); diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs index a506411..626670a 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using System.Threading; using System.Threading.Tasks; namespace MongoDbGenericRepository @@ -29,12 +28,12 @@ namespace MongoDbGenericRepository /// /// The MongoDbContext /// - protected IMongoDbContext MongoDbContext = null; + protected IMongoDbContext MongoDbContext; /// /// A MongoDb Reader for read operations /// - protected IMongoDbReader MongoDbReader = null; + protected IMongoDbReader MongoDbReader; /// /// The constructor taking a connection string and a database name. @@ -63,19 +62,29 @@ namespace MongoDbGenericRepository SetupMongoDbContext(mongoDbContext); } + /// + /// Setups the repository with a . + /// + /// protected void SetupMongoDbContext(IMongoDbContext mongoDbContext) { MongoDbContext = MongoDbContext ?? mongoDbContext; MongoDbReader = MongoDbReader ?? new MongoDbReader(MongoDbContext); } + /// + /// Setups the repository with a connection string and a database name. + /// + /// + /// The database name. If the database name is null or whitespace it is taken from the connection string protected void SetupMongoDbContext(string connectionString, string databaseName) { - if (databaseName == null) + if (string.IsNullOrWhiteSpace(databaseName)) { var mongoUrl = new MongoUrl(connectionString); - databaseName = databaseName ?? mongoUrl.DatabaseName; + databaseName = mongoUrl.DatabaseName; } + ConnectionString = connectionString; DatabaseName = databaseName; SetupMongoDbContext(new MongoDbContext(connectionString, databaseName)); diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs index f6cdc50..9da9cfc 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs @@ -12,6 +12,9 @@ namespace MongoDbGenericRepository { private volatile IMongoDbUpdater _mongoDbUpdater; + /// + /// The MongoDb accessor to update data. + /// protected virtual IMongoDbUpdater MongoDbUpdater { get diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs index 1fbd407..45a9ebd 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs @@ -6,6 +6,10 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { + /// + /// The base Mongo Repository Update interface. used to update documents in the collections. + /// + /// public interface IBaseMongoRepository_Update where TKey : IEquatable { /// diff --git a/MongoDbGenericRepository/Models/IndexCreationOptions.cs b/MongoDbGenericRepository/Models/IndexCreationOptions.cs index ad2d60c..669798c 100644 --- a/MongoDbGenericRepository/Models/IndexCreationOptions.cs +++ b/MongoDbGenericRepository/Models/IndexCreationOptions.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace MongoDbGenericRepository.Models { diff --git a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs index 201de31..7d8325a 100644 --- a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs +++ b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs @@ -1,5 +1,4 @@ using MongoDB.Driver; -using MongoDbGenericRepository.DataAccess.Read; using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; @@ -51,7 +50,7 @@ namespace MongoDbGenericRepository /// The Id of the document you want to get. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -109,7 +108,7 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -180,7 +179,7 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -238,7 +237,7 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// An optional partition key. /// An optional cancellation Token. - public async virtual Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -296,7 +295,7 @@ namespace MongoDbGenericRepository /// A LINQ expression filter. /// An optional partitionKey /// An optional cancellation Token. - public async virtual Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + public virtual async Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) where TDocument : IDocument where TKey : IEquatable { @@ -326,7 +325,7 @@ namespace MongoDbGenericRepository /// A property selector to order by descending. /// An optional partitionKey. /// An optional cancellation Token. - public async virtual Task GetByMaxAsync( + public virtual async Task GetByMaxAsync( Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) @@ -360,7 +359,7 @@ namespace MongoDbGenericRepository /// A property selector for the minimum value you are looking for. /// An optional partitionKey. /// An optional cancellation Token. - public async virtual Task GetByMinAsync(Expression> filter, + public virtual async Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) @@ -395,7 +394,7 @@ namespace MongoDbGenericRepository /// A property selector for the maximum value you are looking for. /// An optional partitionKey. /// An optional cancellation Token. - public async virtual Task GetMaxValueAsync( + public virtual async Task GetMaxValueAsync( Expression> filter, Expression> maxValueSelector, string partitionKey = null,