Esempio n. 1
0
        public IMongoDatabaseBuilder ConfigureCollection <TDocument>(
            IMongoCollectionConfiguration <TDocument> configuration) where TDocument : class
        {
            Action <IMongoDatabase, IMongoCollections> collectionConfigurationAction =
                (mongoDb, mongoCollectionBuilders) =>
            {
                if (mongoCollectionBuilders.Exists <TDocument>())
                {
                    throw new Exception($"The mongo collection configuration for " +
                                        $"document type '{typeof(TDocument)}' already exists.");
                }

                var collectionBuilder = new MongoCollectionBuilder <TDocument>(mongoDb);

                configuration.OnConfiguring(collectionBuilder);

                IMongoCollection <TDocument> configuredCollection =
                    collectionBuilder.Build();

                mongoCollectionBuilders.Add(configuredCollection);
            };

            _collectionActions.Add(collectionConfigurationAction);

            return(this);
        }
Esempio n. 2
0
        public IMongoDatabaseBuilder ConfigureCollection <TDocument>(
            IMongoCollectionConfiguration <TDocument> configuration) where TDocument : class
        {
            Action <IMongoDatabase, Dictionary <Type, object> > buildAction =
                (mongoDb, mongoCollectionBuilders) =>
            {
                if (mongoCollectionBuilders.ContainsKey(typeof(TDocument)))
                {
                    throw new Exception($"The mongo collection configuration for " +
                                        $"document type '{typeof(TDocument)}' already exists.");
                }

                var collectionBuilder = new MongoCollectionBuilder <TDocument>(mongoDb);

                configuration.OnConfiguring(collectionBuilder);
                collectionBuilder.Build();

                mongoCollectionBuilders.Add(typeof(TDocument), collectionBuilder);
            };

            _builderActions.Add(buildAction);

            return(this);
        }