| | | 1 | | using MongoDB.Driver; |
| | | 2 | | |
| | | 3 | | namespace ArturRios.Data.MongoDb; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Wraps an <see cref="IMongoDatabase" /> and carries the ambient client session used to enlist |
| | | 7 | | /// repository operations in the Mongo unit of work transaction. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <param name="database">The MongoDB database.</param> |
| | 18 | 10 | | public class MongoContext(IMongoDatabase database) |
| | | 11 | | { |
| | | 12 | | /// <summary>The ambient transaction session, or <see langword="null" /> when none is active.</summary> |
| | 52 | 13 | | public IClientSessionHandle? Session { get; set; } |
| | | 14 | | |
| | | 15 | | /// <summary>Returns the collection for <typeparamref name="T" /> using the naming convention.</summary> |
| | | 16 | | /// <typeparam name="T">The document type.</typeparam> |
| | | 17 | | public IMongoCollection<T> GetCollection<T>() where T : Document => |
| | 47 | 18 | | database.GetCollection<T>(CollectionName.For<T>()); |
| | | 19 | | } |