Beispiel #1
0
        public CatalogContext(ICatalogDatabaseSettings settings)
        {
            MongoClient    client   = new MongoClient(settings.ConnectionString);
            IMongoDatabase database = client.GetDatabase(settings.DatabaseName);

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

            Products = database.GetCollection <Product>(dbSettings.CollectionName);
            CatalogContextSeed.Seed(Products);
        }
Beispiel #3
0
        public CatalogContext(IConfiguration configuration)
        {
            var client   = new MongoClient(configuration.GetValue <string>("DatabaseSettings:ConnectionString"));            // to create connection to the mongo database
            var database = client.GetDatabase(configuration.GetValue <string>("DatabaseSettings:DatabaseName"));             // if the database on does not exist it will create it

            Products = database.GetCollection <Product>(configuration.GetValue <string>("DatabaseSettings:CollectionName")); // get the collection name from the database object
            CatalogContextSeed.SeedData(Products);                                                                           // check if there is a product in the collection otherwise add some productsto the Collection Passed to it
        }
        public CatalogContext(IConfiguration config)
        {
            var client   = new MongoClient(config.GetValue <string>("DatabaseSettings:ConnectionString"));
            var database = client.GetDatabase(config.GetValue <string>("DatabaseSettings:DatabaseName"));

            Products = database.GetCollection <Product>(config.GetValue <string>("DatabaseSettings:CollectionName"));
            CatalogContextSeed.SeedData(Products);
        }
        public CatalogDBContext(ICatalogDatabaseSetting setting)
        {
            var Client   = new MongoClient(setting.ConnectionString);
            var Database = Client.GetDatabase(setting.DatabaseName);

            Products = Database.GetCollection <Product>(setting.CollectionName);

            CatalogContextSeed.seedData(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);
        }
        public CatalogContext(ICatalogDatabaseSettings catalogDatabaseSettings)
        {
            var client   = new MongoClient(catalogDatabaseSettings.ConnectionString);
            var database = client.GetDatabase(catalogDatabaseSettings.DatabaseName);

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

            CatalogContextSeed.SeedData(this.Products);
        }
Beispiel #8
0
        public CatalogContext(ICatalogDatabaseConfigurations configuration)
        {
            var client   = new MongoClient(configuration.ConnectionString);
            var dataBase = client.GetDatabase(configuration.DatabaseName);

            Products = dataBase.GetCollection <Product>(configuration.CollectionName);

            CatalogContextSeed.SeedData(Products);
        }
Beispiel #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);
        }
        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);
        }
        public CatalogContext(IConfiguration configuration)
        {
            string connectionString = configuration.GetValue<string>("DatabaseSettings:ConnectionString");
            string databaseName = configuration.GetValue<string>("DatabaseSettings:DatabaseName");
            string collectionName = configuration.GetValue<string>("DatabaseSettings:CollectionName");

            var mongoClient = new MongoClient(connectionString);
            var database = mongoClient.GetDatabase(databaseName);

            Products = database.GetCollection<Product>(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);
        }
Beispiel #13
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 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);
        }
Beispiel #15
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);
        }
Beispiel #16
0
        public CatalogContext
        (
            IConfiguration configuration,
            IOptions <DatabaseSettings> databaseSettings
        )
        {
            _databaseSettings = databaseSettings;
            var client   = new MongoClient(_databaseSettings.Value.ConnectionString);
            var database = client.GetDatabase(_databaseSettings.Value.DatabaseName);

            this.Products = database.GetCollection <Product>(_databaseSettings.Value.CollectionName);

            // Fills database with dummy data in case when it is empty.
            bool existProduct = Products.Find(p => true).Any();

            if (!existProduct)
            {
                CatalogContextSeed.SeedData(Products);
            }
        }
Beispiel #17
0
 public CatalogContext(DbContextOptions <CatalogContext> options)
     : base(options)
 {
     CatalogContextSeed.SeedData(this);
 }