Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MongoDBContext.cs 844B

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