コード例 #1
0
        public FoodItemService(IFoodSharingDatabaseSettings settings, DatabaseService databaseService)
        {
            _items = databaseService.Database.GetCollection <FoodItem>(settings.ItemsCollectionName);
            var indexOptions = new CreateIndexOptions {
                Background = false
            };
            var indexKeys = Builders <FoodItem> .IndexKeys.Geo2DSphere(item => item.Position);

            _items.Indexes.CreateOne(new CreateIndexModel <FoodItem>(indexKeys, indexOptions));
        }
コード例 #2
0
        public DatabaseService(IFoodSharingDatabaseSettings settings)
        {
            var credential = MongoCredential.CreateCredential(settings.MasterDatabaseName, settings.DatabaseUser,
                                                              settings.DatabasePassword);
            var mongoClientSettings = new MongoClientSettings
            {
                Credential = credential,
                Server     = new MongoServerAddress(settings.DatabaseServer, settings.DatabasePort)
            };
            var client = new MongoClient(mongoClientSettings);

            Database = client.GetDatabase(settings.DatabaseName);
        }
コード例 #3
0
 public UserService(IFoodSharingDatabaseSettings settings, DatabaseService databaseService)
 {
     _items = databaseService.Database.GetCollection <User>(settings.UsersCollectionName);
 }