You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627
  1. using MongoDB.Driver;
  2. using System.Diagnostics.CodeAnalysis;
  3. namespace Diligent.WebAPI.Data
  4. {
  5. [ExcludeFromCodeCoverage]
  6. public class MongoDBContext : IMongoDBContext
  7. {
  8. private readonly IConfiguration _configuration;
  9. private IMongoDatabase _db { get; set; }
  10. private MongoClient _mongoClient { get; set; }
  11. public IClientSessionHandle Session { get; set; }
  12. public MongoDBContext(IConfiguration configuration)
  13. {
  14. _configuration = configuration;
  15. var mongoDbSettings = _configuration.GetSection("WebApiDB");
  16. _mongoClient = new MongoClient(mongoDbSettings["ConnectionString"]);
  17. _db = _mongoClient.GetDatabase(mongoDbSettings["DatabaseName"]);
  18. }
  19. public IMongoCollection<Request> GetCollection<Request>(string id)
  20. {
  21. return _db.GetCollection<Request>(id);
  22. }
  23. }
  24. }