Beispiel #1
0
        private IMongoClient GetClient(string connectionString, MongoDbCredentials dbCredentials)
        {
            var existingClient = Clients.Where(p => p.Key == connectionString).Select(p => p.Value);

            if (existingClient.Count() >= 1)
            {
                return(existingClient.ElementAt(0));
            }
            else
            {
                var settings = MongoClientSettings.FromConnectionString(connectionString);
                settings.Credential       = MongoCredential.CreateCredential(dbCredentials.UsersDatabase, dbCredentials.Username, dbCredentials.Password);
                Clients[connectionString] = new MongoClient(settings);
            }

            return(Clients[connectionString]);
        }
Beispiel #2
0
 /// <summary>
 /// Creates new instance of <see cref="MongoDbRepositorySettings{T}"/> for a <see cref="MongoDbRepository{T}"/> with secured access.
 /// </summary>
 /// <param name="connectionString">Database connection string</param>
 /// <param name="databaseName">Database name</param>
 /// <param name="collectionName">Collection name</param>
 /// <param name="credentials">Credentials</param>
 public MongoDbRepositorySettings(string connectionString, string databaseName, string collectionName, MongoDbCredentials credentials)
 {
     SetupSerialisationAndMapping();
     Client     = GetClient(connectionString, credentials);
     Database   = GetDatabase(databaseName);
     Collection = GetCollection(collectionName);
 }