-
Notifications
You must be signed in to change notification settings - Fork 1
/
MongoDBContext.cs
43 lines (39 loc) · 1.41 KB
/
MongoDBContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using MongoDB.Driver;
namespace MausWorks.MongoDB
{
/// <summary>
/// Provides templating for future <see cref="MongoDBContext"/>s
/// </summary>
public abstract class MongoDBContext
{
/// <summary>
/// Gets or sets the mongo client.
/// </summary>
/// <value>
/// The mongo client.
/// </value>
internal IMongoClient MongoClient { get; set; }
/// <summary>
/// Gets or sets the database.
/// </summary>
/// <value>
/// The database.
/// </value>
internal IMongoDatabase Database { get; set; }
/// <summary>
/// Creates the a <see cref="IMongoCollection{TDocument}"/> and maps it to the connected database.
/// </summary>
/// <typeparam name="T">The type of the collection</typeparam>
/// <param name="collectionName">The name of the collection as specified in the database.</param>
/// <returns></returns>
public IMongoCollection<T> CreateCollection<T>(string collectionName) where T : class
{
return Database.GetCollection<T>(collectionName);
}
/// <summary>
/// Used to set up and configure the collections in this <see cref="MongoDBContext"/>
/// <para>Called after the context has successfully been created.</para>
/// </summary>
public abstract void SetupCollections();
}
}