예제 #1
0
        /// <summary>
        /// Load Configutaion variables
        /// </summary>
        private void LoadConfigurations()
        {
            _setup    = true;
            _endpoint = this.config.Endpoint;
            _authKey  = this.config.AuthKey;

            if (!string.IsNullOrEmpty(config.ConnectionMode) && !string.IsNullOrEmpty(config.ConnectionProtocol))
            {
                ConnectionMode connMode     = (ConnectionMode)Enum.Parse(typeof(ConnectionMode), config.ConnectionMode, true);
                Protocol       connProtocol = (Protocol)Enum.Parse(typeof(Protocol), config.ConnectionProtocol, true);
                _connPolicy = new ConnectionPolicy()
                {
                    ConnectionMode = connMode, ConnectionProtocol = connProtocol
                };
            }
            else
            {
                _connPolicy = new ConnectionPolicy();
            }

            _databaseId = this.config.DatabaseId;
            _client     = GetConnection();
            _database   = new LightLazy <Database>(async() => await GetOrCreateDatabaseAsync());
            _collection = new LightLazy <DocumentCollection>(async() => await GetOrCreateCollectionAsync());
        }
        /// <summary>
        /// Inject that target of entity
        /// </summary>
        /// <param name="T"></param>
        private void InjectTarget(Type T)
        {
            this._typeToCollectionMap.TryGetValue(T, out LightLazy <DocumentCollection> documentColletionRuntime);

            if (documentColletionRuntime == null)
            {
                _collectionName = T.Name;
                var _collection = new LightLazy <DocumentCollection>(async() => await GetOrCreateCollectionAsync());

                this._typeToCollectionMap.TryAdd(T, _collection);
            }
            else
            {
                _collectionName = T.Name;
            }
        }