using MongoDbGenericRepository.DataAccess.Create; using MongoDbGenericRepository.Models; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace MongoDbGenericRepository { 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. Task AddOneAsync(TDocument document) 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. Task AddManyAsync(IEnumerable documents) 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. /// public abstract partial class BaseMongoRepository : IBaseMongoRepository_Create { private readonly object _initLock = new object(); private MongoDbCreator _mongoDbCreator; protected MongoDbCreator MongoDbCreator { get { if (_mongoDbCreator != null) { return _mongoDbCreator; } lock (_initLock) { if (_mongoDbCreator == null) { _mongoDbCreator = new MongoDbCreator(MongoDbContext); } } return _mongoDbCreator; } } /// /// 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. public virtual async Task AddOneAsync(TDocument document) where TDocument : IDocument where TKey : IEquatable { await MongoDbCreator.AddOneAsync(document); } /// /// 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. public virtual async Task AddOneAsync(TDocument document) where TDocument : IDocument { await MongoDbCreator.AddOneAsync(document); } /// /// 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. public virtual void AddOne(TDocument document) where TDocument : IDocument where TKey : IEquatable { MongoDbCreator.AddOne(document); } /// /// 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. public virtual void AddOne(TDocument document) where TDocument : IDocument { MongoDbCreator.AddOne(document); } /// /// 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. public virtual async Task AddManyAsync(IEnumerable documents) where TDocument : IDocument where TKey : IEquatable { await MongoDbCreator.AddManyAsync(documents); } /// /// 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. public virtual async Task AddManyAsync(IEnumerable documents) where TDocument : IDocument { await MongoDbCreator.AddManyAsync(documents); } /// /// 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. public virtual void AddMany(IEnumerable documents) where TDocument : IDocument where TKey : IEquatable { MongoDbCreator.AddMany(documents); } /// /// 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. public virtual void AddMany(IEnumerable documents) where TDocument : IDocument { MongoDbCreator.AddMany(documents); } } }