Esempio n. 1
0
        /// <summary>
        /// Addition register entities for base MongoDB context
        /// </summary>
        public static IServiceCollection ConfigureMongoDbContext(
            this IServiceCollection services,
            Action <MongoDbContextBuilder <BaseMongoDbContext> > builder)
        {
            var configuration    = new MongoDbContextConfiguration <BaseMongoDbContext>();
            var dbContextBuilder = new MongoDbContextBuilder <BaseMongoDbContext>(services, configuration);

            builder?.Invoke(dbContextBuilder);
            return(services);
        }
Esempio n. 2
0
        /// <summary>
        /// Register MongoDB Context for mongodb server
        /// With different MongoDbContext
        /// </summary>
        public static IServiceCollection AddMongoDbContext <TDbContext>(
            this IServiceCollection services,
            Action <MongoDbContextBuilder <TDbContext> > builder)
            where TDbContext : BaseMongoDbContext
        {
            var configuration    = new MongoDbContextConfiguration <TDbContext>();
            var dbContextBuilder = new MongoDbContextBuilder <TDbContext>(services, configuration);

            builder?.Invoke(dbContextBuilder);

            services.AddSingleton <MongoDbContextConfiguration <TDbContext> >(configuration);

            services.AddSingleton <TDbContext>(r =>
            {
                var dbContextConfiguration = r.GetService <MongoDbContextConfiguration <TDbContext> >();
                return((TDbContext)Activator.CreateInstance(typeof(TDbContext),
                                                            (IMongoDbContextConfiguration)dbContextConfiguration));
            });

            return(services);
        }
Esempio n. 3
0
 public MongoDbContextBuilder(IServiceCollection services, MongoDbContextConfiguration <TDbContext> configuration)
 {
     _services      = services;
     _configuration = configuration;
 }
Esempio n. 4
0
 public MongoRepository(TDbContext context, MongoDbContextConfiguration <TDbContext> configuration)
 {
     _mongoContext  = context;
     _configuration = configuration;
     _dbCollection  = _mongoContext.GetCollection <TEntity>();
 }