public static IServiceCollection AddMongoDb( this IServiceCollection services, MongoDbConfig config) { var mongoDbContext = new MongoDbContext(config.ConnectionString, config.DatabaseName); return(services .AddSingleton <IMongoDbContext>(mongoDbContext) .AddSingleton(config)); }
public static IServiceCollection AddUpdatesProducerMongoRepositories( this IServiceCollection services, MongoDbConfig config) { return(services .AddMongoDb(config) .AddSingleton <MongoApplicationDbContext>() .AddSingleton <IUserLatestUpdateTimesRepository, MongoUserLatestUpdateTimesRepository>() .AddSingleton <ISentUpdatesRepository, MongoSentUpdatesRepository>()); }
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); } }
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); }
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)); }