Ejemplo 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);
        }
        private IMongoCollection <TDocument> AddDefaultCollection <TDocument>()
            where TDocument : class
        {
            IMongoCollection <TDocument> configuredCollection =
                new MongoCollectionBuilder <TDocument>(Database).Build();

            _mongoCollections.Add(configuredCollection);

            return(configuredCollection);
        }
        private MongoCollectionBuilder <TDocument> TryGetCollectionBuilder <TDocument>()
            where TDocument : class
        {
            MongoCollectionBuilder <TDocument> collectionBuilder = null;

            if (_mongoCollectionBuilders.ContainsKey(typeof(TDocument)))
            {
                collectionBuilder = (MongoCollectionBuilder <TDocument>)
                                    _mongoCollectionBuilders[typeof(TDocument)];
            }

            return(collectionBuilder);
        }
        internal IMongoCollection <TDocument> CreateCollection <TDocument>()
            where TDocument : class
        {
            MongoCollectionBuilder <TDocument> collectionBuilder =
                TryGetCollectionBuilder <TDocument>();

            if (collectionBuilder == null)
            {
                collectionBuilder = new MongoCollectionBuilder <TDocument>(Database);
            }

            return(collectionBuilder.Build());
        }
Ejemplo n.º 5
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);
        }