first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Security.Authentication;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Landmark.OLA.Application.DataAccess
|
||||
{
|
||||
// Reference: http://mongodb.github.io/mongo-csharp-driver/2.5
|
||||
public class DataClient : IDataClient
|
||||
{
|
||||
private readonly MongoClientSettings _mongoSettings;
|
||||
private readonly DataAccessConnection _configuration;
|
||||
private readonly MongoClient _client;
|
||||
private readonly IMongoDatabase _database;
|
||||
|
||||
public DataClient(IOptions<DataAccessConnection> settings) {
|
||||
_configuration = settings.Value;
|
||||
_mongoSettings = GetMongoSettings();
|
||||
_client = new MongoClient(_mongoSettings);
|
||||
_database = _client.GetDatabase(_configuration.DatabaseName);
|
||||
}
|
||||
|
||||
public IMongoDatabase GetDatabase()
|
||||
{
|
||||
return _database;
|
||||
}
|
||||
|
||||
private MongoClientSettings GetMongoSettings()
|
||||
{
|
||||
MongoClientSettings settings = new()
|
||||
{
|
||||
Server = new MongoServerAddress(_configuration.Host, _configuration.Port),
|
||||
UseTls = true,
|
||||
SslSettings = new SslSettings()
|
||||
};
|
||||
settings.SslSettings.EnabledSslProtocols = SslProtocols.Tls12;
|
||||
|
||||
MongoIdentity identity = new MongoInternalIdentity(_configuration.DatabaseName, _configuration.UserName);
|
||||
MongoIdentityEvidence evidence = new PasswordEvidence(_configuration.Password);
|
||||
|
||||
settings.Credential = new MongoCredential("SCRAM-SHA-1", identity, evidence);
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user