示例#1
0
        private IMongoCollection <Product> SettingUpDatabase(ICatalogDatabaseSettings settings)
        {
            var client = new MongoClient(_settings.ConnectionString);

            _database = client.GetDatabase(settings.DatabaseName);
            return(SettingUpDataCollection(settings));
        }
示例#2
0
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            _settings = settings;
            Products  = SettingUpDatabase(settings);

            CatalogContextSeed.SeedDataIfEmptyCollection(Products);
        }
 public CatalogContext(ICatalogDatabaseSettings settings)
  {
      var client = new MongoClient(settings.ConnectionString);
      var database = client.GetDatabase(settings.DatabaseName);
      Products = database.GetCollection<Product>(settings.CollectionName);
      CataloContextSeed.SeedData(Products);
  }
        public CatalogContext(ICatalogDatabaseSettings dbSettings)
        {
            var client   = new MongoClient(dbSettings.ConnectionString);
            var database = client.GetDatabase(dbSettings.DatabaseName);

            this.Products = database.GetCollection <Product>(dbSettings.CollectionName);
            CatalogContextSeed.seedData(this.Products);
        }
        private void connectToDatabase(ICatalogDatabaseSettings settings)
        {
            MongoClient    client   = new MongoClient($"{settings.ConnectionString}/{settings.DatabaseName}");
            IMongoDatabase database = client.GetDatabase(settings.DatabaseName);

            Products = database.GetCollection <Product>(settings.CollectionName);

            CatalogContextSeed.SeedData(Products);
        }
示例#6
0
        public CatalogContext(ICatalogDatabaseSettings _catalogDatabaseSettings)
        {
            MongoClient mongoClient = new MongoClient(_catalogDatabaseSettings.ConnectionString);

            IMongoDatabase database = mongoClient.GetDatabase(_catalogDatabaseSettings.DatabaseName);

            Products = database.GetCollection <Product>(_catalogDatabaseSettings.CollectionName);

            CatalogContextSeed.SeedData(Products);
        }
示例#7
0
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            //var client = new MongoClient(settings.ConnectionString);
            var client = new MongoClient("mongodb://*****:*****@ds011111.mongolab.com:11111/CatalogDb?connect=replicaSet");

            _db = client.GetDatabase(settings.Database);

            Products = _db.GetCollection <Product>("Products");
            CatalogContextSeed.SeedData(Products);
        }
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));

            var client   = new MongoClient(_settings.ConnectionString);
            var database = client.GetDatabase(_settings.DatabaseName);

            Products = database.GetCollection <Product>(_settings.CollectionName);

            CatalogContextSeed.SeedData(Products);
        }
示例#9
0
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            //Create mongodb client by using the connection
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            Products = database.GetCollection <Product>(settings.CollectionName);
            //Seeding db here

            CatalogContextSeed.SeedData(Products);
        }
示例#10
0
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            // اتصال برقرار کردن به دیتابیس مونگو
            var client = new MongoClient(settings.ConnectionString);

            // انتخاب دیتابیس مونگو برای کاتالوگ
            var database = client.GetDatabase(settings.DatabaseName);

            // ست کردن کالکشن پروداکت از داخل دیتابیس مونگو
            Products = database.GetCollection <Product>(settings.CollectionName);

            // فرستادن اطلاعات کالکشن برای بررسی داده های آن
            CatalogContextSeed.SeedData(Products);
        }
        public CatalogContext(ICatalogDatabaseSettings catalogSettings)
        {
            // getting instance of CatalogDatabaseSettings
            _catalogSettings = catalogSettings;
            // Getting databse from mongoDb database using connection string and database name
            var client   = new MongoClient(_catalogSettings.ConnectionString);
            var database = client.GetDatabase(_catalogSettings.DatabaseName);

            // getting collection from Catalog database called Products
            Products = database.GetCollection <Product>(_catalogSettings.CollectionName);

            // getting data from collection Product
            CatalogContextSeed.SeedData(Products);
        }
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            // Создадим соединение с MongoDb
            // ConnectionString берется из файла appsettings.json
            MongoClient client = new(connectionString : settings.ConnectionString);
            // Получаем БД в MongoDb
            var database = client.GetDatabase(name: settings.DatabaseName);

            // Загружаем коллекцию продуктов из БД
            // В качестве параметра передаем имя коллекции из appsettings.json
            Products = database.GetCollection <Product>(name: settings.CollectionName);

            // Заполняем коллекцию Products данными
            CatalogContextSeed.SeedData(Products);
        }
示例#13
0
        public CatalogContext(ICatalogDatabaseSettings settings, ILogger <CatalogContext> logger)
        {
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            Connection = new   SqliteConnection(settings.ConnectionString);
            Connection.Open();

            _logger.LogInformation("connection.Open", null);

            Cmd = new SqliteCommand("", Connection);

            // Enable write-ahead logging
            Cmd.CommandText = @"PRAGMA journal_mode = 'wal'";
            Cmd.ExecuteNonQuery();

            CatalogContextSeed.SeedData(Cmd);
        }
示例#14
0
        public GenericRepository(ICatalogDatabaseSettings settings)
        {
            var client = new MongoClient(settings.ConnectionString);

            MongoDatabase = client.GetDatabase(settings.DatabaseName);
        }
示例#15
0
        public MongoContext(ICatalogDatabaseSettings connectionSetting)
        {
            var client = new MongoClient(connectionSetting.ConnectionString);

            Database = client.GetDatabase(connectionSetting.DatabaseName);
        }
 public CatalogContext(ICatalogDatabaseSettings settings)
 {
     connectToDatabase(settings);
 }
示例#17
0
 private IMongoCollection <Product> SettingUpDataCollection(ICatalogDatabaseSettings settings)
 {
     return(_database.GetCollection <Product>(_settings.CollectionName));
 }