Пример #1
0
        /// <summary>
        /// 获取配置信息
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Task <WebSocketOption> GetAsync(string key)
        {
            if (cache.TryGetValue(key, out var webSocketOption))
            {
                return(Task.FromResult(webSocketOption));
            }

            var option = serviceProvider.GetService(MergeNamedType.Get(key)) as WebSocketOption;

            if (option == null)
            {
                return(default);
Пример #2
0
        public DefaultMongoGridFSInfrastructure(MongoContextOptions <TMongoContext> _mongoContextOptions, IMongoClientFactory _mongoClientFactory, IServiceProvider serviceProvider)
        {
            currentContextOptions = _mongoContextOptions;
            //获取mongo客户端信息
            var mongoClientInfo = _mongoClientFactory.GetMongoClient <TMongoContext>();

            //获取客户端
            currentMongoClient = mongoClientInfo.Item1;
            //获取当前上下文信息
            currentMongoContext = serviceProvider.GetService(MergeNamedType.Get(typeof(TMongoContext).Name)) as TMongoContext;
            //构建GridFS对象
            gridFSBucket = Build(currentMongoClient.GetDatabase(mongoClientInfo.Item2.DataBase), currentMongoContext.BucketName);
        }
Пример #3
0
        /// <summary>
        /// 获取客户端
        /// </summary>
        /// <typeparam name="TMongoContext"></typeparam>
        /// <returns></returns>
        public Tuple <IMongoClient, MongoContext> GetMongoClient <TMongoContext>() where TMongoContext : MongoContext
        {
            var contextType = typeof(TMongoContext);
            //从内存中读取mongodb客户端
            var mongoClientInfo = MongoClientPool.Where(a => a.Key == contextType).Select(a => a.Value).FirstOrDefault();

            if (mongoClientInfo != null)
            {
                return(mongoClientInfo);
            }

            //获取上下文信息
            var mongoContextInfo = serviceProvider.GetService(MergeNamedType.Get(contextType.Name)) as TMongoContext;

            mongoContextInfo.CheckNull();
            //实例化mongo客户端信息
            mongoClientInfo = new Tuple <IMongoClient, MongoContext>(new MongoClient(mongoContextInfo.ConnectionString), mongoContextInfo);
            //存储进字典
            MongoClientPool.TryAdd(contextType, mongoClientInfo);
            return(mongoClientInfo);
        }
Пример #4
0
 public EFOptions Get(Type dbContext)
 {
     return(serviceProvider.GetService(MergeNamedType.Get(dbContext.Name)) as EFOptions);
 }
Пример #5
0
 public EFOptions Get <TDbContext>() where TDbContext : DbContext
 {
     return(serviceProvider.GetService(MergeNamedType.Get(typeof(TDbContext).Name)) as EFOptions);
 }