public UserService(IPetDatabaseSettings settings) { string detectedHost = Environment.GetEnvironmentVariable("MONGODB_HOST"); if (detectedHost == null || detectedHost.Equals("")) { detectedHost = settings.ConnectionString; } var client = new MongoClient(detectedHost); var database = client.GetDatabase(settings.DatabaseName); _pets = database.GetCollection <Pet>(settings.PetCollectionName); _users = database.GetCollection <User>(settings.UserCollectionName); }
/// <summary>The constructor <c>PetService</c> will receive setting parameters provided that /// those have been configured accordingly on the Setup.cs file of the solution /// </summary> public PetService(IPetDatabaseSettings settings, List <PetConfigurationSettings> petSettings) { string detectedHost = Environment.GetEnvironmentVariable("MONGODB_HOST"); if (detectedHost == null) { detectedHost = settings.ConnectionString; } var client = new MongoClient(detectedHost); var database = client.GetDatabase(settings.DatabaseName); _petFactory = new PetFactory(petSettings); _pets = database.GetCollection <Pet>(settings.PetCollectionName); _owners = database.GetCollection <User>(settings.UserCollectionName); }