diff --git a/CoreIntegrationTests/CoreIntegrationTests.csproj b/CoreIntegrationTests/CoreIntegrationTests.csproj index e6fec96..2e4ad1b 100644 --- a/CoreIntegrationTests/CoreIntegrationTests.csproj +++ b/CoreIntegrationTests/CoreIntegrationTests.csproj @@ -7,7 +7,7 @@ - + diff --git a/CoreIntegrationTests/Infrastructure/TestRepository.cs b/CoreIntegrationTests/Infrastructure/TestRepository.cs index aaec153..ae2a1d6 100644 --- a/CoreIntegrationTests/Infrastructure/TestRepository.cs +++ b/CoreIntegrationTests/Infrastructure/TestRepository.cs @@ -9,7 +9,7 @@ namespace IntegrationTests.Infrastructure { const string connectionString = "mongodb://localhost:27017"; - private static readonly ITestRepository instance = new TestRepository(connectionString, "MongoDbTests"); + private static readonly ITestRepository _instance = new TestRepository(connectionString, "MongoDbTests"); // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit @@ -26,7 +26,7 @@ namespace IntegrationTests.Infrastructure { get { - return instance; + return _instance; } } diff --git a/IntegrationTests/IntegrationTests.csproj b/IntegrationTests/IntegrationTests.csproj index 2ed74d2..58a2d21 100644 --- a/IntegrationTests/IntegrationTests.csproj +++ b/IntegrationTests/IntegrationTests.csproj @@ -31,16 +31,16 @@ - ..\packages\MongoDbGenericRepository.1.2.0\lib\net45\MongoDB.Bson.dll + ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Bson.dll - ..\packages\MongoDbGenericRepository.1.2.0\lib\net45\MongoDB.Driver.dll + ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.dll - ..\packages\MongoDbGenericRepository.1.2.0\lib\net45\MongoDB.Driver.Core.dll + ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDB.Driver.Core.dll - ..\packages\MongoDbGenericRepository.1.2.0\lib\net45\MongoDbGenericRepository.dll + ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\MongoDbGenericRepository.dll ..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll @@ -50,7 +50,7 @@ - ..\packages\MongoDbGenericRepository.1.2.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + ..\packages\MongoDbGenericRepository.1.2.1\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll diff --git a/IntegrationTests/packages.config b/IntegrationTests/packages.config index f6aeddd..8ef186d 100644 --- a/IntegrationTests/packages.config +++ b/IntegrationTests/packages.config @@ -3,7 +3,7 @@ - + diff --git a/MongoDbGenericRepository.sln b/MongoDbGenericRepository.sln index 29387f9..cb7da2b 100644 --- a/MongoDbGenericRepository.sln +++ b/MongoDbGenericRepository.sln @@ -7,7 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "Integra EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDbGenericRepository", "MongoDbGenericRepository\MongoDbGenericRepository.csproj", "{EFC776C4-2AF3-440C-BE80-3FBE335817A5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoreIntegrationTests", "CoreIntegrationTests\CoreIntegrationTests.csproj", "{C640C106-7A25-4E49-A0CF-E4F248E5A97F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreIntegrationTests", "CoreIntegrationTests\CoreIntegrationTests.csproj", "{C640C106-7A25-4E49-A0CF-E4F248E5A97F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/MongoDbGenericRepository/BaseMongoDbRepository.cs b/MongoDbGenericRepository/BaseMongoDbRepository.cs index 986fbbc..d9e90e5 100644 --- a/MongoDbGenericRepository/BaseMongoDbRepository.cs +++ b/MongoDbGenericRepository/BaseMongoDbRepository.cs @@ -801,11 +801,6 @@ namespace MongoDbGenericRepository { document.Id = Guid.NewGuid(); } - - if (document.AddedAtUtc == default(DateTime)) - { - document.AddedAtUtc = DateTime.UtcNow; - } } #endregion diff --git a/MongoDbGenericRepository/IMongoDbContext.cs b/MongoDbGenericRepository/IMongoDbContext.cs index c2b0591..31fee2a 100644 --- a/MongoDbGenericRepository/IMongoDbContext.cs +++ b/MongoDbGenericRepository/IMongoDbContext.cs @@ -8,6 +8,16 @@ namespace MongoDbGenericRepository /// public interface IMongoDbContext { + /// + /// The IMongoClient from the official MongoDb driver + /// + IMongoClient Client { get; } + + /// + /// The IMongoDatabase from the official Mongodb driver + /// + IMongoDatabase Database { get; } + /// /// The private GetCollection method /// diff --git a/MongoDbGenericRepository/Models/IDocument.cs b/MongoDbGenericRepository/Models/IDocument.cs index 0facbaa..bdad597 100644 --- a/MongoDbGenericRepository/Models/IDocument.cs +++ b/MongoDbGenericRepository/Models/IDocument.cs @@ -8,10 +8,6 @@ namespace MongoDbGenericRepository.Models /// public interface IDocument { - /// - /// The date and UTC time at which the document was added to the collection. - /// - DateTime AddedAtUtc { get; set; } /// /// The Guid, which must be decorated with the [BsonId] attribute /// if you want the MongoDb C# driver to consider it to be the document ID. diff --git a/MongoDbGenericRepository/MongoDbContext.cs b/MongoDbGenericRepository/MongoDbContext.cs index 71bb8d8..dd21e9d 100644 --- a/MongoDbGenericRepository/MongoDbContext.cs +++ b/MongoDbGenericRepository/MongoDbContext.cs @@ -8,8 +8,15 @@ namespace MongoDbGenericRepository /// public class MongoDbContext : IMongoDbContext { - private readonly IMongoClient _client; - private readonly IMongoDatabase _database; + /// + /// The IMongoClient from the official MongoDb driver + /// + public IMongoClient Client { get; } + + /// + /// The IMongoDatabase from the official Mongodb driver + /// + public IMongoDatabase Database { get; } static MongoDbContext() { @@ -17,15 +24,25 @@ namespace MongoDbGenericRepository MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard; } + /// + /// The constructor of the MongoDbContext, it needs a an object implementing . + /// + /// An object implementing IMongoDatabase + public MongoDbContext(IMongoDatabase mongoDatabase) + { + Database = mongoDatabase; + Client = Database.Client; + } + /// /// The constructor of the MongoDbContext, it needs a connection string and a database name. /// - /// - /// + /// The connections string. + /// The name of your database. public MongoDbContext(string connectionString, string databaseName) { - _client = new MongoClient(connectionString); - _database = _client.GetDatabase(databaseName); + Client = new MongoClient(connectionString); + Database = Client.GetDatabase(databaseName); } /// @@ -35,7 +52,7 @@ namespace MongoDbGenericRepository /// public IMongoCollection GetCollection() { - return _database.GetCollection(Pluralize()); + return Database.GetCollection(Pluralize()); } /// @@ -45,7 +62,7 @@ namespace MongoDbGenericRepository /// The value of the partition key. public IMongoCollection GetCollection(string partitionKey) where TDocument : IDocument { - return _database.GetCollection(partitionKey +"-"+ Pluralize()); + return Database.GetCollection(partitionKey +"-"+ Pluralize()); } /// @@ -54,7 +71,7 @@ namespace MongoDbGenericRepository /// public void DropCollection() { - _database.DropCollection(Pluralize()); + Database.DropCollection(Pluralize()); } /// @@ -63,7 +80,7 @@ namespace MongoDbGenericRepository /// public void DropCollection(string partitionKey) { - _database.DropCollection(partitionKey + "-" + Pluralize()); + Database.DropCollection(partitionKey + "-" + Pluralize()); } /// diff --git a/MongoDbGenericRepository/MongoDbGenericRepository.nuspec b/MongoDbGenericRepository/MongoDbGenericRepository.nuspec index e13058c..6aba088 100644 --- a/MongoDbGenericRepository/MongoDbGenericRepository.nuspec +++ b/MongoDbGenericRepository/MongoDbGenericRepository.nuspec @@ -2,7 +2,7 @@ MongoDbGenericRepository - 1.2 + 1.2.1 MongoDb Generic Repository Alexandre Spieser Alexandre Spieser @@ -10,7 +10,7 @@ https://github.com/alexandre-spieser/mongodb-generic-repository false A generic repository implementation using the MongoDB C# Sharp 2.0 driver. - .NET Core support added. + Exposed core MongoDb driver objects and removed the AddedAtUtc property constraint from the IDocument interface. Copyright 2017 (c) Alexandre Spieser. All rights reserved. MongoDb Repository Generic NoSql diff --git a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll index 6c63b64..c5464da 100644 Binary files a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll and b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.dll differ diff --git a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml index dcf020f..9afe743 100644 --- a/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/lib/net45/MongoDbGenericRepository.xml @@ -561,6 +561,16 @@ This is the interface of the IMongoDbContext which is managed by the . + + + The IMongoClient from the official MongoDb driver + + + + + The IMongoDatabase from the official Mongodb driver + + The private GetCollection method @@ -618,11 +628,6 @@ Your document must implement this class in order for the MongoDbRepository to handle them. - - - The date and UTC time at which the document was added to the collection. - - The Guid, which must be decorated with the [BsonId] attribute @@ -673,12 +678,28 @@ The MongoDb context + + + The IMongoClient from the official MongoDb driver + + + + + The IMongoDatabase from the official Mongodb driver + + + + + The constructor of the MongoDbContext, it needs a an object implementing . + + An object implementing IMongoDatabase + The constructor of the MongoDbContext, it needs a connection string and a database name. - - + The connections string. + The name of your database. diff --git a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll index 02726da..62f6c98 100644 Binary files a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll and b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.dll differ diff --git a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml index dcf020f..9afe743 100644 --- a/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/lib/netstandard1.5/MongoDbGenericRepository.xml @@ -561,6 +561,16 @@ This is the interface of the IMongoDbContext which is managed by the . + + + The IMongoClient from the official MongoDb driver + + + + + The IMongoDatabase from the official Mongodb driver + + The private GetCollection method @@ -618,11 +628,6 @@ Your document must implement this class in order for the MongoDbRepository to handle them. - - - The date and UTC time at which the document was added to the collection. - - The Guid, which must be decorated with the [BsonId] attribute @@ -673,12 +678,28 @@ The MongoDb context + + + The IMongoClient from the official MongoDb driver + + + + + The IMongoDatabase from the official Mongodb driver + + + + + The constructor of the MongoDbContext, it needs a an object implementing . + + An object implementing IMongoDatabase + The constructor of the MongoDbContext, it needs a connection string and a database name. - - + The connections string. + The name of your database. diff --git a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll index fafd6bb..8a408e0 100644 Binary files a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll and b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.dll differ diff --git a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml index dcf020f..9afe743 100644 --- a/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml +++ b/MongoDbGenericRepository/lib/netstandard2.0/MongoDbGenericRepository.xml @@ -561,6 +561,16 @@ This is the interface of the IMongoDbContext which is managed by the . + + + The IMongoClient from the official MongoDb driver + + + + + The IMongoDatabase from the official Mongodb driver + + The private GetCollection method @@ -618,11 +628,6 @@ Your document must implement this class in order for the MongoDbRepository to handle them. - - - The date and UTC time at which the document was added to the collection. - - The Guid, which must be decorated with the [BsonId] attribute @@ -673,12 +678,28 @@ The MongoDb context + + + The IMongoClient from the official MongoDb driver + + + + + The IMongoDatabase from the official Mongodb driver + + + + + The constructor of the MongoDbContext, it needs a an object implementing . + + An object implementing IMongoDatabase + The constructor of the MongoDbContext, it needs a connection string and a database name. - - + The connections string. + The name of your database.