Esempio n. 1
0
        public DbProvider(DbProviderOptions options)
        {
            if (options.ConnectionString.Contains(","))
            {
                var cs = options.ConnectionString.Split(',').Where(x => !string.IsNullOrEmpty(x?.Trim())).ToList();
                if (cs.Count() > 1)
                {
                    ConnectionString = cs[0];
                    cs.RemoveAt(0);
                    ConnectionReadString = cs.ToArray();
                }
                else if (cs.Count() == 1)
                {
                    ConnectionString = cs[0];
                }
            }
            else
            {
                ConnectionString = options.ConnectionString;
            }

            Name = options.Name;
            //ConnectionString = connectionString;
            ConnectionType                = options.ConnectionType;
            UseParameterPrefixInSql       = options.UseParameterPrefixInSql;
            UseParameterPrefixInParameter = options.UseParameterPrefixInParameter;
            ParameterPrefix               = options.ParameterPrefix;
            UseQuotationInSql             = options.UseQuotationInSql;
            Debug = options.Debug;
        }
Esempio n. 2
0
        /// <summary>
        /// 通过入参初始化驱动程序
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tag"></param>
        /// <param name="connectionString"></param>
        /// <param name="connectionType"></param>
        /// <param name="useParameterPrefixInSql"></param>
        /// <param name="useParameterPrefixInParameter"></param>
        /// <param name="parameterPrefix"></param>
        /// <param name="useQuotationInSql"></param>
        /// <param name="debug"></param>
        public static void Set(DbProviderOptions options)
        {
            var dbProvider = new DbProvider(options);

            if (DbProviderConfigCache.Count > DbProviderConfigCacheSize)
            {
                DbProviderConfigCache.Clear();
            }
            if (_dbProvider == null)
            {
                lock (_obj_lock)
                {
                    if (_dbProvider == null)
                    {
                        _dbProvider = dbProvider;
                    }
                }
            }
            DbProviderConfigCache[options.Name] = dbProvider;
            //注入默认服务
            dbProvider.AddService <IMigrateProvider, DefaultMigrateProvider>();
            dbProvider.AddService <IPageProvider, DefaultPageProvider>();
        }