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]); }
public MongoDbRepositorySettings(string connectionString, string databaseName, string collectionName, MongoDbCredentials credentials) { SetupSerialisationAndMapping(); Client = GetClient(connectionString, credentials); Database = GetDatabase(databaseName); Collection = GetCollection(collectionName); }