Ejemplo n.º 1
0
        public static void Initialize(StactiveMongoOptions options)
        {
            _client       = new MongoClient(options.ConnectionString);
            _databaseName = options.DatabaseName;

            CreateIndexes(options);
        }
Ejemplo n.º 2
0
        private static void CreateIndexes(StactiveMongoOptions options)
        {
            var instance    = new StactiveMongoDb();
            var requestLogs = instance.GetCollection <RequestLog>(options.RequestLogCollectionName);

            requestLogs.Indexes.CreateMany(new[]
            {
                new CreateIndexModel <RequestLog>(Builders <RequestLog> .IndexKeys.Ascending(x => x.Url)),
                new CreateIndexModel <RequestLog>(Builders <RequestLog> .IndexKeys.Ascending(x => x.UserId)),
            });
        }
Ejemplo n.º 3
0
        public static IServiceCollection AddStactiveMongoPersistance(this IServiceCollection services, Action <StactiveMongoOptions> options = null)
        {
            services.AddTransient <IPersistence, MongoDbPersistence>();

            var stactiveMongoOptions = new StactiveMongoOptions();

            options?.Invoke(stactiveMongoOptions);
            services.AddTransient(c => stactiveMongoOptions);

            StactiveMongoDb.Initialize(stactiveMongoOptions);
            services.AddTransient <StactiveMongoDb>();
            return(services);
        }
Ejemplo n.º 4
0
 public MongoDbPersistence(StactiveMongoDb stactiveMongoDb, StactiveMongoOptions options)
 {
     _collection = stactiveMongoDb.GetCollection <RequestLog>(options.RequestLogCollectionName);
 }