예제 #1
0
 public MongoGameRepository(ILoggerFactory loggerFactory, MongoDatabaseOptions mongoDatabaseOptions) : base(
         loggerFactory, mongoDatabaseOptions)
 {
     // todo move this to a seeder
     if (Collection.EstimatedDocumentCount() == 0)
     {
         Collection.InsertOne(new Game(1, "IDENTITEIT", 5, 30));
         Collection.InsertOne(new Game(2, "PASSWORD", 4, 20));
     }
 }
예제 #2
0
        protected MongoRepository(ILoggerFactory loggerFactory, MongoDatabaseOptions mongoDatabaseOptions)
        {
            ILogger logger = loggerFactory.CreateLogger <MongoGameRepository>();

            try
            {
                MongoClient client;
                try
                {
                    var mongoClientSettings = new MongoClientSettings
                    {
                        Server = MongoServerAddress.Parse(mongoDatabaseOptions.ConnectionString)
                    };
                    client = new MongoClient(mongoClientSettings);
                }
                catch
                {
                    client = new MongoClient(mongoDatabaseOptions.ConnectionString);
                }

                var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
                if (string.IsNullOrWhiteSpace(environment))
                {
                    environment = "Development";
                }

                var mongoDatabase = client.GetDatabase($"{mongoDatabaseOptions.DatabaseName}-{environment}");
                Collection = mongoDatabase.GetCollection <T>(typeof(T).Name);
            }
            catch (Exception exception)
            {
                logger.LogCritical(
                    $"Error while connecting to {mongoDatabaseOptions.ConnectionString}.", exception);
                throw;
            }
        }
예제 #3
0
 public MongoGameSessionRepository(ILoggerFactory loggerFactory, MongoDatabaseOptions mongoDatabaseOptions) :
     base(loggerFactory, mongoDatabaseOptions)
 {
 }