コード例 #1
0
        /// <summary>
        /// 注册mongodb服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static IServiceCollection AddMongodb(this IServiceCollection services, string connectionString)
        {
            MongoConfig mongoConfig = new MongoConfig(connectionString);

            services.AddTransient(typeof(IMongoService), _ => new MongoService(mongoConfig));
            return(services);
        }
コード例 #2
0
        /// <summary>
        /// 注册mongodb服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="connectionString"></param>
        /// <param name="typeService"></param>
        /// <returns></returns>
        public static IServiceCollection AddMongodb(this IServiceCollection services, string connectionString, Type typeService = null)
        {
            if (typeService == null)
            {
                typeService = typeof(IMongoService);
            }
            MongoConfig mongoConfig = new MongoConfig(connectionString);

            services.AddTransient(typeService, _ => new MongoService(mongoConfig));
            return(services);
        }
コード例 #3
0
ファイル: MongoService.cs プロジェクト: shi-tou/yezi_fang
        /// <summary>
        /// 初始化实例
        /// </summary>
        /// <param name="config"></param>
        public MongoService(MongoConfig config)
        {
            MongoClient client = new MongoClient(config.Host);

            MongoDatabase = client.GetDatabase(config.DatabaseName);
        }