Exposed core MongoDb driver objects and removed the AddedAtUtc property constraint from the IDocument interface.
This commit is contained in:
@@ -801,11 +801,6 @@ namespace MongoDbGenericRepository
|
||||
{
|
||||
document.Id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
if (document.AddedAtUtc == default(DateTime))
|
||||
{
|
||||
document.AddedAtUtc = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -8,6 +8,16 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
public interface IMongoDbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The IMongoClient from the official MongoDb driver
|
||||
/// </summary>
|
||||
IMongoClient Client { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The IMongoDatabase from the official Mongodb driver
|
||||
/// </summary>
|
||||
IMongoDatabase Database { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The private GetCollection method
|
||||
/// </summary>
|
||||
|
||||
@@ -8,10 +8,6 @@ namespace MongoDbGenericRepository.Models
|
||||
/// </summary>
|
||||
public interface IDocument
|
||||
{
|
||||
/// <summary>
|
||||
/// The date and UTC time at which the document was added to the collection.
|
||||
/// </summary>
|
||||
DateTime AddedAtUtc { get; set; }
|
||||
/// <summary>
|
||||
/// 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.
|
||||
|
||||
@@ -8,8 +8,15 @@ namespace MongoDbGenericRepository
|
||||
/// </summary>
|
||||
public class MongoDbContext : IMongoDbContext
|
||||
{
|
||||
private readonly IMongoClient _client;
|
||||
private readonly IMongoDatabase _database;
|
||||
/// <summary>
|
||||
/// The IMongoClient from the official MongoDb driver
|
||||
/// </summary>
|
||||
public IMongoClient Client { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The IMongoDatabase from the official Mongodb driver
|
||||
/// </summary>
|
||||
public IMongoDatabase Database { get; }
|
||||
|
||||
static MongoDbContext()
|
||||
{
|
||||
@@ -17,15 +24,25 @@ namespace MongoDbGenericRepository
|
||||
MongoDefaults.GuidRepresentation = MongoDB.Bson.GuidRepresentation.Standard;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor of the MongoDbContext, it needs a an object implementing <see cref="IMongoDatabase"/>.
|
||||
/// </summary>
|
||||
/// <param name="mongoDatabase">An object implementing IMongoDatabase</param>
|
||||
public MongoDbContext(IMongoDatabase mongoDatabase)
|
||||
{
|
||||
Database = mongoDatabase;
|
||||
Client = Database.Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor of the MongoDbContext, it needs a connection string and a database name.
|
||||
/// </summary>
|
||||
/// <param name="connectionString"></param>
|
||||
/// <param name="databaseName"></param>
|
||||
/// <param name="connectionString">The connections string.</param>
|
||||
/// <param name="databaseName">The name of your database.</param>
|
||||
public MongoDbContext(string connectionString, string databaseName)
|
||||
{
|
||||
_client = new MongoClient(connectionString);
|
||||
_database = _client.GetDatabase(databaseName);
|
||||
Client = new MongoClient(connectionString);
|
||||
Database = Client.GetDatabase(databaseName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,7 +52,7 @@ namespace MongoDbGenericRepository
|
||||
/// <returns></returns>
|
||||
public IMongoCollection<TDocument> GetCollection<TDocument>()
|
||||
{
|
||||
return _database.GetCollection<TDocument>(Pluralize<TDocument>());
|
||||
return Database.GetCollection<TDocument>(Pluralize<TDocument>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -45,7 +62,7 @@ namespace MongoDbGenericRepository
|
||||
/// <param name="partitionKey">The value of the partition key.</param>
|
||||
public IMongoCollection<TDocument> GetCollection<TDocument>(string partitionKey) where TDocument : IDocument
|
||||
{
|
||||
return _database.GetCollection<TDocument>(partitionKey +"-"+ Pluralize<TDocument>());
|
||||
return Database.GetCollection<TDocument>(partitionKey +"-"+ Pluralize<TDocument>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +71,7 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
public void DropCollection<TDocument>()
|
||||
{
|
||||
_database.DropCollection(Pluralize<TDocument>());
|
||||
Database.DropCollection(Pluralize<TDocument>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,7 +80,7 @@ namespace MongoDbGenericRepository
|
||||
/// <typeparam name="TDocument"></typeparam>
|
||||
public void DropCollection<TDocument>(string partitionKey)
|
||||
{
|
||||
_database.DropCollection(partitionKey + "-" + Pluralize<TDocument>());
|
||||
Database.DropCollection(partitionKey + "-" + Pluralize<TDocument>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>MongoDbGenericRepository</id>
|
||||
<version>1.2</version>
|
||||
<version>1.2.1</version>
|
||||
<title>MongoDb Generic Repository</title>
|
||||
<authors>Alexandre Spieser</authors>
|
||||
<owners>Alexandre Spieser</owners>
|
||||
@@ -10,7 +10,7 @@
|
||||
<projectUrl>https://github.com/alexandre-spieser/mongodb-generic-repository</projectUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>A generic repository implementation using the MongoDB C# Sharp 2.0 driver.</description>
|
||||
<releaseNotes>.NET Core support added.</releaseNotes>
|
||||
<releaseNotes>Exposed core MongoDb driver objects and removed the AddedAtUtc property constraint from the IDocument interface.</releaseNotes>
|
||||
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||
<tags>MongoDb Repository Generic NoSql</tags>
|
||||
</metadata>
|
||||
|
||||
Binary file not shown.
@@ -561,6 +561,16 @@
|
||||
This is the interface of the IMongoDbContext which is managed by the <see cref="T:MongoDbGenericRepository.BaseMongoRepository"/>.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.IMongoDbContext.Client">
|
||||
<summary>
|
||||
The IMongoClient from the official MongoDb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.IMongoDbContext.Database">
|
||||
<summary>
|
||||
The IMongoDatabase from the official Mongodb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.IMongoDbContext.GetCollection``1">
|
||||
<summary>
|
||||
The private GetCollection method
|
||||
@@ -618,11 +628,6 @@
|
||||
Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.Models.IDocument.AddedAtUtc">
|
||||
<summary>
|
||||
The date and UTC time at which the document was added to the collection.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.Models.IDocument.Id">
|
||||
<summary>
|
||||
The Guid, which must be decorated with the [BsonId] attribute
|
||||
@@ -673,12 +678,28 @@
|
||||
The MongoDb context
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.MongoDbContext.Client">
|
||||
<summary>
|
||||
The IMongoClient from the official MongoDb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.MongoDbContext.Database">
|
||||
<summary>
|
||||
The IMongoDatabase from the official Mongodb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.#ctor(MongoDB.Driver.IMongoDatabase)">
|
||||
<summary>
|
||||
The constructor of the MongoDbContext, it needs a an object implementing <see cref="T:MongoDB.Driver.IMongoDatabase"/>.
|
||||
</summary>
|
||||
<param name="mongoDatabase">An object implementing IMongoDatabase</param>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.#ctor(System.String,System.String)">
|
||||
<summary>
|
||||
The constructor of the MongoDbContext, it needs a connection string and a database name.
|
||||
</summary>
|
||||
<param name="connectionString"></param>
|
||||
<param name="databaseName"></param>
|
||||
<param name="connectionString">The connections string.</param>
|
||||
<param name="databaseName">The name of your database.</param>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.GetCollection``1">
|
||||
<summary>
|
||||
|
||||
Binary file not shown.
@@ -561,6 +561,16 @@
|
||||
This is the interface of the IMongoDbContext which is managed by the <see cref="T:MongoDbGenericRepository.BaseMongoRepository"/>.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.IMongoDbContext.Client">
|
||||
<summary>
|
||||
The IMongoClient from the official MongoDb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.IMongoDbContext.Database">
|
||||
<summary>
|
||||
The IMongoDatabase from the official Mongodb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.IMongoDbContext.GetCollection``1">
|
||||
<summary>
|
||||
The private GetCollection method
|
||||
@@ -618,11 +628,6 @@
|
||||
Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.Models.IDocument.AddedAtUtc">
|
||||
<summary>
|
||||
The date and UTC time at which the document was added to the collection.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.Models.IDocument.Id">
|
||||
<summary>
|
||||
The Guid, which must be decorated with the [BsonId] attribute
|
||||
@@ -673,12 +678,28 @@
|
||||
The MongoDb context
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.MongoDbContext.Client">
|
||||
<summary>
|
||||
The IMongoClient from the official MongoDb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.MongoDbContext.Database">
|
||||
<summary>
|
||||
The IMongoDatabase from the official Mongodb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.#ctor(MongoDB.Driver.IMongoDatabase)">
|
||||
<summary>
|
||||
The constructor of the MongoDbContext, it needs a an object implementing <see cref="T:MongoDB.Driver.IMongoDatabase"/>.
|
||||
</summary>
|
||||
<param name="mongoDatabase">An object implementing IMongoDatabase</param>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.#ctor(System.String,System.String)">
|
||||
<summary>
|
||||
The constructor of the MongoDbContext, it needs a connection string and a database name.
|
||||
</summary>
|
||||
<param name="connectionString"></param>
|
||||
<param name="databaseName"></param>
|
||||
<param name="connectionString">The connections string.</param>
|
||||
<param name="databaseName">The name of your database.</param>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.GetCollection``1">
|
||||
<summary>
|
||||
|
||||
Binary file not shown.
@@ -561,6 +561,16 @@
|
||||
This is the interface of the IMongoDbContext which is managed by the <see cref="T:MongoDbGenericRepository.BaseMongoRepository"/>.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.IMongoDbContext.Client">
|
||||
<summary>
|
||||
The IMongoClient from the official MongoDb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.IMongoDbContext.Database">
|
||||
<summary>
|
||||
The IMongoDatabase from the official Mongodb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.IMongoDbContext.GetCollection``1">
|
||||
<summary>
|
||||
The private GetCollection method
|
||||
@@ -618,11 +628,6 @@
|
||||
Your document must implement this class in order for the MongoDbRepository to handle them.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.Models.IDocument.AddedAtUtc">
|
||||
<summary>
|
||||
The date and UTC time at which the document was added to the collection.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.Models.IDocument.Id">
|
||||
<summary>
|
||||
The Guid, which must be decorated with the [BsonId] attribute
|
||||
@@ -673,12 +678,28 @@
|
||||
The MongoDb context
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.MongoDbContext.Client">
|
||||
<summary>
|
||||
The IMongoClient from the official MongoDb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:MongoDbGenericRepository.MongoDbContext.Database">
|
||||
<summary>
|
||||
The IMongoDatabase from the official Mongodb driver
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.#ctor(MongoDB.Driver.IMongoDatabase)">
|
||||
<summary>
|
||||
The constructor of the MongoDbContext, it needs a an object implementing <see cref="T:MongoDB.Driver.IMongoDatabase"/>.
|
||||
</summary>
|
||||
<param name="mongoDatabase">An object implementing IMongoDatabase</param>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.#ctor(System.String,System.String)">
|
||||
<summary>
|
||||
The constructor of the MongoDbContext, it needs a connection string and a database name.
|
||||
</summary>
|
||||
<param name="connectionString"></param>
|
||||
<param name="databaseName"></param>
|
||||
<param name="connectionString">The connections string.</param>
|
||||
<param name="databaseName">The name of your database.</param>
|
||||
</member>
|
||||
<member name="M:MongoDbGenericRepository.MongoDbContext.GetCollection``1">
|
||||
<summary>
|
||||
|
||||
Reference in New Issue
Block a user