Exemple #1
0
        public MongoDbEventStore(IOptions <MongoDbConfig> settings)
        {
            var config = settings.Value ?? throw new ArgumentNullException(nameof(settings));

            UserEventsClassMapRegistry.LoadClassMapRegistry();

            var client = new MongoClient(new MongoClientSettings
            {
                Server     = new MongoServerAddress(config.ConnectionString, config.Port),
                Credential = MongoCredential.CreateCredential(config.DatabaseName, config.User, config.Password)
            });

            var db = client.GetDatabase(config.DatabaseName);

            this.collection = db.GetCollection <EventDescription>("eventDescriptions", new MongoCollectionSettings
            {
                GuidRepresentation = GuidRepresentation.CSharpLegacy
            });

            if (this.collection == null)
            {
                db.CreateCollection("eventStreamStore");
            }
        }
Exemple #2
0
        public EventStreamEventStore(IOptions <MongoDbConfig> settings)
        {
            var config = settings.Value;

            UserEventsClassMapRegistry.LoadClassMapRegistry();

            var client = new MongoClient(new MongoClientSettings
            {
                Server     = new MongoServerAddress(config.ConnectionString, config.Port),
                Credential = MongoCredential.CreateCredential(config.DatabaseName, config.User, config.Password)
            });

            var db = client.GetDatabase(config.DatabaseName);

            if (CollectionExists(db, CollectionName))
            {
                this.collection = db.GetCollection <EventStream>(CollectionName, collectionOptions);
            }
            else
            {
                db.CreateCollection(CollectionName);
                this.collection = db.GetCollection <EventStream>(CollectionName, collectionOptions);
            }
        }