Exemplo n.º 1
0
        public DefaultMongoDB(IOptions <DocumentStoreOptions> documentOptions, IOptions <MongoDBOptions> mongoOptions, ILogger <DefaultMongoDB> logger)
        {
            _logger = logger;

            _documentOptions = documentOptions.Value;
            _mongoOptions    = mongoOptions.Value;

            _clientDict     = new Dictionary <string, IMongoClient>();
            _dbDict         = new Dictionary <string, IMongoDatabase>();
            _collectionDict = new Dictionary <string, object>();
        }
Exemplo n.º 2
0
        /// <summary>
        ///     根据文档类型不同调用不同的仓储工厂服务
        /// </summary>
        /// <param name="documentStoreType"></param>
        /// <returns></returns>
        public IDocumentStore Create(string documentStoreType)
        {
            documentStoreType = documentStoreType.ToLower();
            //todo:初始化文档类型,统一变成小写。
            var options = new DocumentStoreOptions();

            options.Stores.Add(GithubDocumentStore.Type.ToLower(), typeof(GithubDocumentStore));
            options.Stores.Add(FileSystemDocumentStore.Type.ToLower(), typeof(FileSystemDocumentStore));
            options.Stores.Add(GitlabDocumentStore.Type.ToLower(), typeof(GitlabDocumentStore));

            var serviceType = options.Stores.GetOrDefault(documentStoreType);


            if (serviceType == null)
            {
                throw new ApplicationException($"当前文档类型的仓储服务不存在: {documentStoreType}");
            }

            var service = (IDocumentStore)_serviceProvider.GetRequiredService(serviceType);

            return(service);
        }