diff --git a/CoreIntegrationTests/CoreIntegrationTests.csproj b/CoreIntegrationTests/CoreIntegrationTests.csproj index 493a082..49ae519 100644 --- a/CoreIntegrationTests/CoreIntegrationTests.csproj +++ b/CoreIntegrationTests/CoreIntegrationTests.csproj @@ -1,13 +1,13 @@  - netcoreapp2.1 + net6.0 - + all diff --git a/CoreUnitTests/CoreUnitTests.csproj b/CoreUnitTests/CoreUnitTests.csproj new file mode 100644 index 0000000..35cd8dc --- /dev/null +++ b/CoreUnitTests/CoreUnitTests.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/CoreUnitTests/UnitTest1.cs b/CoreUnitTests/UnitTest1.cs new file mode 100644 index 0000000..8db911c --- /dev/null +++ b/CoreUnitTests/UnitTest1.cs @@ -0,0 +1,11 @@ +using Xunit; + +namespace CoreUnitTests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository.sln b/MongoDbGenericRepository.sln index cb7da2b..9d1e6d8 100644 --- a/MongoDbGenericRepository.sln +++ b/MongoDbGenericRepository.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDbGenericRepository", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreIntegrationTests", "CoreIntegrationTests\CoreIntegrationTests.csproj", "{C640C106-7A25-4E49-A0CF-E4F248E5A97F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreUnitTests", "CoreUnitTests\CoreUnitTests.csproj", "{8BE513ED-84F4-47E1-946D-84958CF95E6B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Debug|Any CPU.Build.0 = Debug|Any CPU {C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Release|Any CPU.ActiveCfg = Release|Any CPU {C640C106-7A25-4E49-A0CF-E4F248E5A97F}.Release|Any CPU.Build.0 = Release|Any CPU + {8BE513ED-84F4-47E1-946D-84958CF95E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8BE513ED-84F4-47E1-946D-84958CF95E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8BE513ED-84F4-47E1-946D-84958CF95E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8BE513ED-84F4-47E1-946D-84958CF95E6B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MongoDbGenericRepository/BaseMongoRepository.Create.cs b/MongoDbGenericRepository/BaseMongoRepository.Create.cs index 70d20e5..13465b4 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Create.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Create.cs @@ -7,59 +7,6 @@ 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 - { - /// - /// Asynchronously adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to add. - /// An optional cancellation Token. - Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to add. - void AddOne(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Asynchronously adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The documents you want to add. - /// An optional cancellation Token. - Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The documents you want to add. - void AddMany(IEnumerable documents) - where TDocument : IDocument - where TKey : IEquatable; - } - /// /// 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. @@ -67,12 +14,12 @@ namespace MongoDbGenericRepository public abstract partial class BaseMongoRepository : IBaseMongoRepository_Create { private readonly object _initLock = new object(); - private MongoDbCreator _mongoDbCreator; + private volatile IMongoDbCreator _mongoDbCreator; /// /// The MongoDbCreator field. /// - protected virtual MongoDbCreator MongoDbCreator + protected virtual IMongoDbCreator MongoDbCreator { get { diff --git a/MongoDbGenericRepository/BaseMongoRepository.Delete.cs b/MongoDbGenericRepository/BaseMongoRepository.Delete.cs index e86b060..cba59a8 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Delete.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Delete.cs @@ -7,105 +7,11 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { - public interface IBaseMongoRepository_Delete : IBaseMongoRepository_Delete - { - /// - /// Deletes a document. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to delete. - /// The number of documents deleted. - long DeleteOne(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Asynchronously deletes a document matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The document you want to delete. - /// The number of documents deleted. - Task DeleteOneAsync(TDocument document) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Deletes a document matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - long DeleteOne(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Asynchronously deletes a document matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - Task DeleteOneAsync(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - Task DeleteManyAsync(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Asynchronously deletes a list of documents. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The list of documents to delete. - /// The number of documents deleted. - Task DeleteManyAsync(IEnumerable documents) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Deletes a list of documents. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The list of documents to delete. - /// The number of documents deleted. - long DeleteMany(IEnumerable documents) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Deletes the documents matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - long DeleteMany(Expression> filter, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - } - public abstract partial class BaseMongoRepository : IBaseMongoRepository_Delete { - private MongoDbEraser _mongoDbEraser; - protected virtual MongoDbEraser MongoDbEraser + private volatile IMongoDbEraser _mongoDbEraser; + + protected virtual IMongoDbEraser MongoDbEraser { get { diff --git a/MongoDbGenericRepository/BaseMongoRepository.Index.cs b/MongoDbGenericRepository/BaseMongoRepository.Index.cs index fa97458..f74972a 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Index.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Index.cs @@ -7,113 +7,15 @@ using MongoDbGenericRepository.Models; namespace MongoDbGenericRepository { - public interface IBaseMongoRepository_Index : IBaseMongoRepository_Index - { - /// - /// 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. - Task> GetIndexesNamesAsync(string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Creates an index on the given field in descending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Creates a hashed index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Creates a combined text index. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The fields we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - - /// - /// Drops the index given a field name - /// - /// The type representing a Document. - /// The type of the primary key for a Document. - /// The name of the index - /// An optional partition key - Task DropIndexAsync(string indexName, string partitionKey = null) - where TDocument : IDocument - where TKey : IEquatable; - } /// /// 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_Index { - private MongoDbIndexHandler _mongoDbIndexHandler; - protected virtual MongoDbIndexHandler MongoDbIndexHandler + private volatile IMongoDbIndexHandler _mongoDbIndexHandler; + + protected virtual IMongoDbIndexHandler MongoDbIndexHandler { get { diff --git a/MongoDbGenericRepository/BaseMongoRepository.Main.cs b/MongoDbGenericRepository/BaseMongoRepository.Main.cs index 09664e8..f86f9c7 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Main.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Main.cs @@ -24,7 +24,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected BaseMongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext) @@ -32,7 +32,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected BaseMongoRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase) diff --git a/MongoDbGenericRepository/BaseMongoRepository.Update.cs b/MongoDbGenericRepository/BaseMongoRepository.Update.cs index 82306b1..c4272f5 100644 --- a/MongoDbGenericRepository/BaseMongoRepository.Update.cs +++ b/MongoDbGenericRepository/BaseMongoRepository.Update.cs @@ -13,8 +13,9 @@ namespace MongoDbGenericRepository /// public abstract partial class BaseMongoRepository : IBaseMongoRepository_Update { - private MongoDbUpdater _mongoDbUpdater; - protected virtual MongoDbUpdater MongoDbUpdater + private volatile IMongoDbUpdater _mongoDbUpdater; + + protected virtual IMongoDbUpdater MongoDbUpdater { get { diff --git a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs index eded8d5..a59d0b4 100644 --- a/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs +++ b/MongoDbGenericRepository/DataAccess/Base/DataAccessBase.cs @@ -10,7 +10,7 @@ namespace MongoDbGenericRepository.DataAccess.Base /// /// A base class for accessing the Database and its Collections. /// - public class DataAccessBase + public class DataAccessBase : IDataAccessBase { /// /// The MongoDbContext diff --git a/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs b/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs new file mode 100644 index 0000000..b81ea09 --- /dev/null +++ b/MongoDbGenericRepository/DataAccess/Base/IDataAccessBase.cs @@ -0,0 +1,56 @@ +using System; +using System.Linq.Expressions; +using MongoDB.Driver; +using MongoDB.Driver.Linq; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository.DataAccess.Base +{ + public interface IDataAccessBase + { + /// + /// 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/IMongoDbCreator.cs b/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs new file mode 100644 index 0000000..018b8c4 --- /dev/null +++ b/MongoDbGenericRepository/DataAccess/Create/IMongoDbCreator.cs @@ -0,0 +1,106 @@ +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 +{ + public interface IMongoDbCreator : IDataAccessBase + { + /// + /// Asynchronously adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + /// An optional cancellation Token. + Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + void AddOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + /// An optional cancellation Token. + Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + 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 7847030..de95085 100644 --- a/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs +++ b/MongoDbGenericRepository/DataAccess/Create/MongoDbCreator.cs @@ -14,7 +14,7 @@ namespace MongoDbGenericRepository.DataAccess.Create /// /// A class to insert MongoDb document. /// - public class MongoDbCreator : DataAccessBase + public class MongoDbCreator : DataAccessBase, IMongoDbCreator { /// /// The construct of the MongoDbCreator class. diff --git a/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs b/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs new file mode 100644 index 0000000..43eec28 --- /dev/null +++ b/MongoDbGenericRepository/DataAccess/Delete/IMongoDbEraser.cs @@ -0,0 +1,151 @@ +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 +{ + public interface IMongoDbEraser : IDataAccessBase + { + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to delete. + /// The number of documents deleted. + long DeleteOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to delete. + /// The number of documents deleted. + Task DeleteOneAsync(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + Task DeleteManyAsync(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + long DeleteMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + 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 1daabac..b28d027 100644 --- a/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs +++ b/MongoDbGenericRepository/DataAccess/Delete/MongoDbEraser.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Delete { - public class MongoDbEraser : DataAccessBase + public class MongoDbEraser : DataAccessBase, IMongoDbEraser { public MongoDbEraser(IMongoDbContext mongoDbContext) : base(mongoDbContext) { diff --git a/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs b/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs new file mode 100644 index 0000000..b9b8338 --- /dev/null +++ b/MongoDbGenericRepository/DataAccess/Index/IMongoDbIndexHandler.cs @@ -0,0 +1,156 @@ +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 +{ + public interface IMongoDbIndexHandler : IDataAccessBase + { + /// + /// 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. + Task> GetIndexesNamesAsync(string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates an index on the given field in ascending order. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates an index on the given field in descending order. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The name of the index + /// An optional partition key + 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 6662670..dbf1b9a 100644 --- a/MongoDbGenericRepository/DataAccess/Index/MongoDbIndexHandler.cs +++ b/MongoDbGenericRepository/DataAccess/Index/MongoDbIndexHandler.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Index { - public class MongoDbIndexHandler : DataAccessBase + public class MongoDbIndexHandler : DataAccessBase, IMongoDbIndexHandler { public MongoDbIndexHandler(IMongoDbContext mongoDbContext) : base(mongoDbContext) { diff --git a/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs b/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs new file mode 100644 index 0000000..f3c6e38 --- /dev/null +++ b/MongoDbGenericRepository/DataAccess/Read/IMongoDbReader.cs @@ -0,0 +1,631 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 +{ + public interface IMongoDbReader : IDataAccessBase + { + /// + /// Asynchronously returns a projected document matching the filter condition. + /// + /// 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. + /// 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; + + /// + /// Returns a projected document matching the filter condition. + /// + /// 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. + TProjection ProjectOne(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Asynchronously returns a list of projected documents matching the filter condition. + /// + /// 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. + /// 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. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The type representing the model you want to project to. + /// The document filter. + /// The projection expression. + /// An optional partition key. + List ProjectMany(Expression> filter, Expression> projection, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class; + + /// + /// Groups 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. + /// The grouping criteria. + /// The projected group result. + /// The partition key of your document, if any. + List GroupBy( + Expression> groupingCriteria, + Expression, TProjection>> groupProjection, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// 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. + List GroupBy( + Expression> filter, + Expression> selector, + Expression, TProjection>> projection, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable + where TProjection : class, new(); + + /// + /// 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. + 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(); + + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// The property selector. + /// Order of the sorting. + /// 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, + Expression> sortSelector, + bool ascending = true, + int skipNumber = 0, + int takeNumber = 50, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a paginated list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// The sort definition. + /// 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, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + /// An optional cancellation Token. + Task GetByIdAsync(TKey id, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given its id. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The Id of the document you want to get. + /// An optional partition key. + TDocument GetById(TKey id, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task GetOneAsync(FilterDefinition condition, FindOptions findOption = null, + string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// An optional cancellation Token. + Task GetOneAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given filter definition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + TDocument GetOne(FilterDefinition condition, FindOptions findOption = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns one document given an expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + TDocument GetOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a collection cursor. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + IFindFluent GetCursor(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partition key. + /// An optional cancellation Token. + Task AnyAsync(FilterDefinition condition, CountOptions countOption = null, string partitionKey = null, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// An optional cancellation Token. + Task AnyAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partition key. + bool Any(FilterDefinition condition, CountOptions countOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns true if any of the document of the collection matches the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + bool Any(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + /// An optional cancellation Token. + Task> GetAllAsync(FilterDefinition condition, + FindOptions findOption = null, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// An optional cancellation Token. + Task> GetAllAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb filter option. + /// An optional partition key. + List GetAll(FilterDefinition condition, FindOptions findOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Returns a list of the documents matching the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + List GetAll(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partitionKey + /// An optional cancellation Token. + Task CountAsync(FilterDefinition condition, CountOptions countOption = null, + string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + /// An optional cancellation Token. + Task CountAsync(Expression> filter, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A mongodb filter definition. + /// A mongodb counting option. + /// An optional partitionKey + long Count(FilterDefinition condition, CountOptions countOption = null, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Counts how many documents match the filter condition. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partitionKey + long Count(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetByMaxAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the maximum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by descending. + /// An optional partitionKey. + TDocument GetByMax(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetByMinAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the document with the minimum value of a specified property in a MongoDB collections that is satisfying the filter. + /// + /// The document type. + /// The type of the primary key. + /// A LINQ expression filter. + /// A property selector to order by ascending. + /// An optional partitionKey. + TDocument GetByMin(Expression> filter, Expression> minValueSelector, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// 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. + /// An optional partitionKey. + /// An optional cancellation Token. + Task GetMaxValueAsync(Expression> filter, Expression> maxValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the maximum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// 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. + /// An optional partitionKey. + TValue GetMaxValue(Expression> filter, Expression> maxValueSelector, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// 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. + /// An optional partition key. + /// An optional cancellation Token. + Task GetMinValueAsync(Expression> filter, Expression> minValueSelector, string partitionKey = null, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Gets the minimum value of a property in a mongodb collections that is satisfying the filter. + /// + /// The document type. + /// 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. + /// An optional partition key. + TValue GetMinValue(Expression> filter, Expression> minValueSelector, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// 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, + CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// 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, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + int SumBy(Expression> filter, + Expression> selector, + string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Sums the values of a selected field for a given filtered collection of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// The field you want to sum. + /// The partition key of your document, if any. + decimal SumBy(Expression> filter, + Expression> selector, + 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.Project.cs b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs index 378e86e..61639ee 100644 --- a/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs +++ b/MongoDbGenericRepository/DataAccess/Read/MongoDbReader.Project.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Read { - public partial class MongoDbReader + public partial class MongoDbReader : IMongoDbReader { /// /// Asynchronously returns a projected document matching the filter condition. diff --git a/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs b/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs new file mode 100644 index 0000000..7550d16 --- /dev/null +++ b/MongoDbGenericRepository/DataAccess/Update/IMongoDbUpdater.cs @@ -0,0 +1,432 @@ +using System; +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 +{ + public interface IMongoDbUpdater : IDataAccessBase + { + /// + /// 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. + Task UpdateOneAsync(TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + Task UpdateOneAsync(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + Task UpdateOneAsync(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + Task UpdateOneAsync(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + bool UpdateOne(TDocument modifiedDocument) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + bool UpdateOne(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + bool UpdateOne(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + bool UpdateOne(IClientSessionHandle session, TDocument modifiedDocument, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, UpdateDefinition update, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + bool UpdateOne(IClientSessionHandle session, TDocument documentToModify, Expression> field, TField value, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + bool UpdateOne(IClientSessionHandle session, FilterDefinition filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + /// + bool UpdateOne(IClientSessionHandle session, Expression> filter, Expression> field, TField value, string partitionKey = null, CancellationToken cancellationToken = default(CancellationToken)) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateManyAsync(Expression> filter, UpdateDefinition update, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// 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. + 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) + where TDocument : IDocument + where TKey : IEquatable; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs b/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs index 2a4cdbd..8fc8c93 100644 --- a/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs +++ b/MongoDbGenericRepository/DataAccess/Update/MongoDbUpdater.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository.DataAccess.Update { - public partial class MongoDbUpdater : DataAccessBase + public partial class MongoDbUpdater : DataAccessBase, IMongoDbUpdater { public MongoDbUpdater(IMongoDbContext mongoDbContext) : base(mongoDbContext) { diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Create.cs b/MongoDbGenericRepository/IBaseMongoRepository.Create.cs new file mode 100644 index 0000000..8dc50e3 --- /dev/null +++ b/MongoDbGenericRepository/IBaseMongoRepository.Create.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MongoDbGenericRepository.Models; + +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 + { + /// + /// Asynchronously adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + /// An optional cancellation Token. + Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to add. + void AddOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + /// An optional cancellation Token. + Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The documents you want to add. + void AddMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs b/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs new file mode 100644 index 0000000..06b2134 --- /dev/null +++ b/MongoDbGenericRepository/IBaseMongoRepository.Delete.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository +{ + public interface IBaseMongoRepository_Delete : IBaseMongoRepository_Delete + { + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to delete. + /// The number of documents deleted. + long DeleteOne(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The document you want to delete. + /// The number of documents deleted. + Task DeleteOneAsync(TDocument document) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + Task DeleteManyAsync(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The list of documents to delete. + /// The number of documents deleted. + long DeleteMany(IEnumerable documents) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteMany(Expression> filter, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/IBaseMongoRepository.Index.cs b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs new file mode 100644 index 0000000..2b711f4 --- /dev/null +++ b/MongoDbGenericRepository/IBaseMongoRepository.Index.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository +{ + public interface IBaseMongoRepository_Index : IBaseMongoRepository_Index + { + /// + /// 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. + Task> GetIndexesNamesAsync(string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates an index on the given field in ascending order. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates an index on the given field in descending order. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The fields we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The type of the primary key for a Document. + /// The name of the index + /// An optional partition key + Task DropIndexAsync(string indexName, string partitionKey = null) + where TDocument : IDocument + where TKey : IEquatable; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs index 98131fd..3b9c28f 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Create.cs @@ -7,59 +7,18 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { - /// - /// The interface exposing data insertion functionality for Key typed repositories. - /// - /// - public interface IBaseMongoRepository_Create where TKey : IEquatable - { - /// - /// Asynchronously adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The document you want to add. - /// An optional cancellation Token. - Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument; - - /// - /// Adds a document to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The document you want to add. - void AddOne(TDocument document) where TDocument : IDocument; - - /// - /// Asynchronously adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The documents you want to add. - /// An optional cancellation Token. - Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument; - - /// - /// Adds a list of documents to the collection. - /// Populates the Id and AddedAtUtc fields if necessary. - /// - /// The type representing a Document. - /// The documents you want to add. - void AddMany(IEnumerable documents) where TDocument : IDocument; - } - /// /// 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 { - private MongoDbCreator _mongoDbCreator; + private volatile IMongoDbCreator _mongoDbCreator; /// /// The MongoDb accessor to insert data. /// - protected virtual MongoDbCreator MongoDbCreator + protected virtual IMongoDbCreator MongoDbCreator { get { diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs index 7324b2e..b77ad4f 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Delete.cs @@ -7,98 +7,15 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { - /// - /// The interface exposing deletion functionality for Key typed repositories. - /// - /// The type of the document Id. - public interface IBaseMongoRepository_Delete where TKey : IEquatable - { - /// - /// Deletes a document. - /// - /// The type representing a Document. - /// The document you want to delete. - /// The number of documents deleted. - long DeleteOne(TDocument document) - where TDocument : IDocument; - - /// - /// Asynchronously deletes a document matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// The document you want to delete. - /// The number of documents deleted. - Task DeleteOneAsync(TDocument document) - where TDocument : IDocument; - - /// - /// Deletes a document matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - long DeleteOne(Expression> filter, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Asynchronously deletes a document matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - Task DeleteOneAsync(Expression> filter, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - Task DeleteManyAsync(Expression> filter, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Asynchronously deletes a list of documents. - /// - /// The type representing a Document. - /// The list of documents to delete. - /// The number of documents deleted. - Task DeleteManyAsync(IEnumerable documents) - where TDocument : IDocument; - - /// - /// Deletes a list of documents. - /// - /// The type representing a Document. - /// The list of documents to delete. - /// The number of documents deleted. - long DeleteMany(IEnumerable documents) - where TDocument : IDocument; - - /// - /// Deletes the documents matching the condition of the LINQ expression filter. - /// - /// The type representing a Document. - /// A LINQ expression filter. - /// An optional partition key. - /// The number of documents deleted. - long DeleteMany(Expression> filter, string partitionKey = null) - where TDocument : IDocument; - } - public abstract partial class BaseMongoRepository: IBaseMongoRepository_Delete where TKey : IEquatable { - private MongoDbEraser _mongoDbEraser; + private volatile IMongoDbEraser _mongoDbEraser; /// /// The MongoDb accessor to delete data. /// - protected virtual MongoDbEraser MongoDbEraser + protected virtual IMongoDbEraser MongoDbEraser { get { diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs index c0847ba..7363be5 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Index.cs @@ -7,96 +7,6 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { - /// - /// The interface exposing index management functionality for Key typed repositories. - /// - /// - public interface IBaseMongoRepository_Index where TKey : IEquatable - { - /// - /// Returns the names of the indexes present on a collection. - /// - /// The type representing a Document. - /// An optional partition key - /// A list containing the names of the indexes on on the concerned collection. - Task> GetIndexesNamesAsync(string partitionKey = null) - where TDocument : IDocument; - - /// - /// Create a text index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Creates an index on the given field in ascending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Creates an index on the given field in descending order. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Creates a hashed index on the given field. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The field we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Creates a combined text index. - /// IndexCreationOptions can be supplied to further specify - /// how the creation should be done. - /// - /// The type representing a Document. - /// The fields we want to index. - /// Options for creating an index. - /// An optional partition key. - /// The result of the create index operation. - Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Drops the index given a field name - /// - /// The type representing a Document. - /// The name of the index - /// An optional partition key - Task DropIndexAsync(string indexName, string partitionKey = null) - where TDocument : IDocument; - } - /// /// 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. @@ -104,12 +14,12 @@ namespace MongoDbGenericRepository public abstract partial class BaseMongoRepository : IBaseMongoRepository_Index where TKey : IEquatable { - private MongoDbIndexHandler _mongoDbIndexHandler; + private volatile IMongoDbIndexHandler _mongoDbIndexHandler; /// /// The MongoDb accessor to manage indexes. /// - protected virtual MongoDbIndexHandler MongoDbIndexHandler + protected virtual IMongoDbIndexHandler MongoDbIndexHandler { get { @@ -122,6 +32,7 @@ namespace MongoDbGenericRepository _mongoDbIndexHandler = new MongoDbIndexHandler(MongoDbContext); } } + return _mongoDbIndexHandler; } set { _mongoDbIndexHandler = value; } diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Main.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Main.cs index ed47b0a..eeca6ab 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Main.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Main.cs @@ -4,20 +4,6 @@ using System; namespace MongoDbGenericRepository { - /// - /// The interface exposing all the CRUD and Index functionalities for Key typed repositories. - /// - /// The type of the document Id. - public interface IBaseMongoRepository : - IReadOnlyMongoRepository, - IBaseMongoRepository_Create, - IBaseMongoRepository_Delete, - IBaseMongoRepository_Index, - IBaseMongoRepository_Update - where TKey : IEquatable - { - } - /// /// 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. @@ -41,7 +27,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected BaseMongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext) @@ -49,7 +35,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected BaseMongoRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase) diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs index cdbb862..a506411 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.ReadOnly.cs @@ -34,7 +34,7 @@ namespace MongoDbGenericRepository /// /// A MongoDb Reader for read operations /// - protected MongoDbReader MongoDbReader = null; + protected IMongoDbReader MongoDbReader = null; /// /// The constructor taking a connection string and a database name. @@ -47,7 +47,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDatabase mongoDatabase) : this(new MongoDbContext(mongoDatabase)) @@ -55,7 +55,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDbContext mongoDbContext) diff --git a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs index b56d9c4..f6cdc50 100644 --- a/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs +++ b/MongoDbGenericRepository/KeyTypedRepository/BaseMongoRepository.TKey.Update.cs @@ -7,204 +7,12 @@ using System.Threading.Tasks; namespace MongoDbGenericRepository { - public interface IBaseMongoRepository_Update where TKey : IEquatable - { - /// - /// Asynchronously Updates a document. - /// - /// The type representing a Document. - /// The document with the modifications you want to persist. - Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument; - - /// - /// Updates a document. - /// - /// The type representing a Document. - /// The document with the modifications you want to persist. - bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument; - - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document you want to modify. - /// The update definition for the document. - Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) - where TDocument : IDocument; - - /// - /// Takes a document you want to modify and applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document you want to modify. - /// The update definition for the document. - bool UpdateOne(TDocument documentToModify, UpdateDefinition update) - where TDocument : IDocument; - - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. - bool UpdateOne(TDocument documentToModify, Expression> field, TField value) - where TDocument : IDocument; - - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing a Document. - /// The type of the field. - /// The document you want to modify. - /// The field selector. - /// The new value of the property field. - Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) - where TDocument : IDocument; - - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing 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. - bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing 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. - bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// Updates the property field with the given value update a property field in entities. - /// - /// The type representing 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. - Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entity selected by the filter, updates the property field with the given value. - /// - /// The type representing 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. - Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing 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. - Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing 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. - Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing 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. - long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, updates the property field with the given value. - /// - /// The type representing 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. - long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) - where TDocument : IDocument; - - /// - /// For the entities selected by the filter, applies the update you have defined in MongoDb. - /// - /// The type representing a Document. - /// The document filter. - /// The update definition to apply. - /// The value of the partition key. - long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) - where TDocument : IDocument; - } - public abstract partial class BaseMongoRepository : IBaseMongoRepository_Update where TKey : IEquatable { - private MongoDbUpdater _mongoDbUpdater; - protected virtual MongoDbUpdater MongoDbUpdater + private volatile IMongoDbUpdater _mongoDbUpdater; + + protected virtual IMongoDbUpdater MongoDbUpdater { get { diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Create.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Create.cs new file mode 100644 index 0000000..8994fde --- /dev/null +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Create.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository +{ + /// + /// The interface exposing data insertion functionality for Key typed repositories. + /// + /// + public interface IBaseMongoRepository_Create where TKey : IEquatable + { + /// + /// Asynchronously adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + /// An optional cancellation Token. + Task AddOneAsync(TDocument document, CancellationToken cancellationToken = default) where TDocument : IDocument; + + /// + /// Adds a document to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The document you want to add. + void AddOne(TDocument document) where TDocument : IDocument; + + /// + /// Asynchronously adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The documents you want to add. + /// An optional cancellation Token. + Task AddManyAsync(IEnumerable documents, CancellationToken cancellationToken = default) where TDocument : IDocument; + + /// + /// Adds a list of documents to the collection. + /// Populates the Id and AddedAtUtc fields if necessary. + /// + /// The type representing a Document. + /// The documents you want to add. + void AddMany(IEnumerable documents) where TDocument : IDocument; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Delete.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Delete.cs new file mode 100644 index 0000000..fabb293 --- /dev/null +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Delete.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository +{ + /// + /// The interface exposing deletion functionality for Key typed repositories. + /// + /// The type of the document Id. + public interface IBaseMongoRepository_Delete where TKey : IEquatable + { + /// + /// Deletes a document. + /// + /// The type representing a Document. + /// The document you want to delete. + /// The number of documents deleted. + long DeleteOne(TDocument document) + where TDocument : IDocument; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// The document you want to delete. + /// The number of documents deleted. + Task DeleteOneAsync(TDocument document) + where TDocument : IDocument; + + /// + /// Deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteOne(Expression> filter, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Asynchronously deletes a document matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteOneAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Asynchronously deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + Task DeleteManyAsync(Expression> filter, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Asynchronously deletes a list of documents. + /// + /// The type representing a Document. + /// The list of documents to delete. + /// The number of documents deleted. + Task DeleteManyAsync(IEnumerable documents) + where TDocument : IDocument; + + /// + /// Deletes a list of documents. + /// + /// The type representing a Document. + /// The list of documents to delete. + /// The number of documents deleted. + long DeleteMany(IEnumerable documents) + where TDocument : IDocument; + + /// + /// Deletes the documents matching the condition of the LINQ expression filter. + /// + /// The type representing a Document. + /// A LINQ expression filter. + /// An optional partition key. + /// The number of documents deleted. + long DeleteMany(Expression> filter, string partitionKey = null) + where TDocument : IDocument; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs new file mode 100644 index 0000000..951904b --- /dev/null +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Index.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository +{ + /// + /// The interface exposing index management functionality for Key typed repositories. + /// + /// + public interface IBaseMongoRepository_Index where TKey : IEquatable + { + /// + /// Returns the names of the indexes present on a collection. + /// + /// The type representing a Document. + /// An optional partition key + /// A list containing the names of the indexes on on the concerned collection. + Task> GetIndexesNamesAsync(string partitionKey = null) + where TDocument : IDocument; + + /// + /// Create a text index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateTextIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Creates an index on the given field in ascending order. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateAscendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Creates an index on the given field in descending order. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateDescendingIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Creates a hashed index on the given field. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The field we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateHashedIndexAsync(Expression> field, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Creates a combined text index. + /// IndexCreationOptions can be supplied to further specify + /// how the creation should be done. + /// + /// The type representing a Document. + /// The fields we want to index. + /// Options for creating an index. + /// An optional partition key. + /// The result of the create index operation. + Task CreateCombinedTextIndexAsync(IEnumerable>> fields, IndexCreationOptions indexCreationOptions = null, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Drops the index given a field name + /// + /// The type representing a Document. + /// The name of the index + /// An optional partition key + Task DropIndexAsync(string indexName, string partitionKey = null) + where TDocument : IDocument; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs new file mode 100644 index 0000000..1fbd407 --- /dev/null +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.Update.cs @@ -0,0 +1,201 @@ +using System; +using System.Linq.Expressions; +using System.Threading.Tasks; +using MongoDB.Driver; +using MongoDbGenericRepository.Models; + +namespace MongoDbGenericRepository +{ + public interface IBaseMongoRepository_Update where TKey : IEquatable + { + /// + /// Asynchronously Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + Task UpdateOneAsync(TDocument modifiedDocument) where TDocument : IDocument; + + /// + /// Updates a document. + /// + /// The type representing a Document. + /// The document with the modifications you want to persist. + bool UpdateOne(TDocument modifiedDocument) where TDocument : IDocument; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + Task UpdateOneAsync(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument; + + /// + /// Takes a document you want to modify and applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document you want to modify. + /// The update definition for the document. + bool UpdateOne(TDocument documentToModify, UpdateDefinition update) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + bool UpdateOne(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing a Document. + /// The type of the field. + /// The document you want to modify. + /// The field selector. + /// The new value of the property field. + Task UpdateOneAsync(TDocument documentToModify, Expression> field, TField value) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing 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. + bool UpdateOne(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. + /// + /// The type representing 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. + bool UpdateOne(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// Updates the property field with the given value update a property field in entities. + /// + /// The type representing 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. + Task UpdateOneAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entity selected by the filter, updates the property field with the given value. + /// + /// The type representing 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. + Task UpdateOneAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing 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. + Task UpdateManyAsync(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing 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. + Task UpdateManyAsync(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + Task UpdateManyAsync(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing 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. + long UpdateMany(Expression> filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, updates the property field with the given value. + /// + /// The type representing 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. + long UpdateMany(FilterDefinition filter, Expression> field, TField value, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + long UpdateMany(FilterDefinition filter, UpdateDefinition updateDefinition, string partitionKey = null) + where TDocument : IDocument; + + /// + /// For the entities selected by the filter, applies the update you have defined in MongoDb. + /// + /// The type representing a Document. + /// The document filter. + /// The update definition to apply. + /// The value of the partition key. + long UpdateMany(Expression> filter, UpdateDefinition updateDefinition, string partitionKey = null) + where TDocument : IDocument; + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.cs b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.cs new file mode 100644 index 0000000..f290c27 --- /dev/null +++ b/MongoDbGenericRepository/KeyTypedRepository/IBaseMongoRepository.TKey.cs @@ -0,0 +1,18 @@ +using System; + +namespace MongoDbGenericRepository +{ + /// + /// The interface exposing all the CRUD and Index functionalities for Key typed repositories. + /// + /// The type of the document Id. + public interface IBaseMongoRepository : + IReadOnlyMongoRepository, + IBaseMongoRepository_Create, + IBaseMongoRepository_Delete, + IBaseMongoRepository_Index, + IBaseMongoRepository_Update + where TKey : IEquatable + { + } +} \ No newline at end of file diff --git a/MongoDbGenericRepository/MongoDbGenericRepository.csproj b/MongoDbGenericRepository/MongoDbGenericRepository.csproj index aeeb853..45c60c1 100644 --- a/MongoDbGenericRepository/MongoDbGenericRepository.csproj +++ b/MongoDbGenericRepository/MongoDbGenericRepository.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0; + netstandard2.1;net48 true MongoDbGenericRepository 1.4.8 diff --git a/MongoDbGenericRepository/MongoDbGenericRepository.xml b/MongoDbGenericRepository/MongoDbGenericRepository.xml index 9805841..cc35bd8 100644 --- a/MongoDbGenericRepository/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/MongoDbGenericRepository.xml @@ -2364,13 +2364,13 @@ - The contructor taking a . + The constructor taking a . A mongodb context implementing - The contructor taking a . + The constructor taking a . A mongodb context implementing @@ -3360,13 +3360,13 @@ - The contructor taking a . + The constructor taking a . A mongodb context implementing - The contructor taking a . + The constructor taking a . A mongodb context implementing @@ -3757,13 +3757,13 @@ - The contructor taking a . + The constructor taking a . A mongodb context implementing - The contructor taking a . + The constructor taking a . A mongodb context implementing @@ -4492,13 +4492,13 @@ - The contructor taking a . + The constructor taking a . A mongodb context implementing - The contructor taking a . + The constructor taking a . A mongodb context implementing diff --git a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs index 1959003..201de31 100644 --- a/MongoDbGenericRepository/ReadOnlyMongoRepository.cs +++ b/MongoDbGenericRepository/ReadOnlyMongoRepository.cs @@ -26,7 +26,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext) @@ -34,7 +34,7 @@ namespace MongoDbGenericRepository } /// - /// The contructor taking a . + /// The constructor taking a . /// /// A mongodb context implementing protected ReadOnlyMongoRepository(IMongoDatabase mongoDatabase) : base(mongoDatabase)