예제 #1
0
        public static IServiceCollection AddMongoDb(
            this IServiceCollection services,
            MongoDbConfig config)
        {
            var mongoDbContext = new MongoDbContext(config.ConnectionString, config.DatabaseName);

            return(services
                   .AddSingleton <IMongoDbContext>(mongoDbContext)
                   .AddSingleton(config));
        }
예제 #2
0
 public static IServiceCollection AddUpdatesProducerMongoRepositories(
     this IServiceCollection services,
     MongoDbConfig config)
 {
     return(services
            .AddMongoDb(config)
            .AddSingleton <MongoApplicationDbContext>()
            .AddSingleton <IUserLatestUpdateTimesRepository, MongoUserLatestUpdateTimesRepository>()
            .AddSingleton <ISentUpdatesRepository, MongoSentUpdatesRepository>());
 }
예제 #3
0
        public MongoSentUpdatesRepository(
            MongoApplicationDbContext context,
            MongoDbConfig config)
        {
            _collection = context.SentUpdates;

            if (!_collection.Indexes.List().Any()) // There shouldn't be more than one index in the collection
            {
                CreateExpirationIndex(config);
            }
        }
예제 #4
0
        private void CreateExpirationIndex(MongoDbConfig config)
        {
            IndexKeysDefinition <SentUpdate> keys = Builders <SentUpdate> .IndexKeys
                                                    .Ascending(update => update.SentAt);

            var options = new CreateIndexOptions
            {
                ExpireAfter = config.SentUpdatesExpiration ?? TimeSpan.FromDays(1)
            };
            var indexModel = new CreateIndexModel <SentUpdate>(keys, options);

            _collection.Indexes.CreateOne(indexModel);
        }
예제 #5
0
        public static IServiceCollection AddUpdatesProducer <TProvider>(
            this IServiceCollection services,
            MongoDbConfig mongoDbConfig,
            RabbitMqConfig rabbitMqConfig,
            UpdatesProviderBaseConfig updatesProviderBaseConfig,
            PollerConfig pollerConfig,
            VideoExtractorConfig videoExtractorConfig) where TProvider : class, IUpdatesProvider
        {
            services = mongoDbConfig != null
                ? services.AddUpdatesProducerMongoRepositories(mongoDbConfig)
                : services.AddUpdatesProducerMockRepositories();

            return(services
                   .AddRabbitMqUpdatesPublisher(rabbitMqConfig)
                   .AddVideoExtractor(videoExtractorConfig)
                   .AddUpdatesProvider <TProvider>(updatesProviderBaseConfig)
                   .AddUpdatesPollerService(pollerConfig));
        }