/// <summary> 注册适配器。</summary> /// <param name="adapter">适配器。</param> /// <exception cref="NotSupportedException">适配器已在运作,禁止修改!</exception> public static void RegisterAdapter(IDbConnectionLtsAdapter adapter) { if (adapter is null) { throw new ArgumentNullException(nameof(adapter)); } if (string.IsNullOrWhiteSpace(adapter.ProviderName)) { throw new DException("数据库适配器名称不能为空!"); } Adapters[adapter.ProviderName.ToLower()] = adapter; }
/// <summary> /// 获取数据仓促供应器。 /// </summary> /// <param name="adapter">适配器。</param> /// <returns></returns> public static IDatabaseFor GetOrCreate(IDbConnectionLtsAdapter adapter) { if (adapter is null) { throw new ArgumentNullException(nameof(adapter)); } if (DatabaseForCache.TryGetValue(adapter, out IDatabaseFor databaseFor)) { return(databaseFor); } if (DatabaseFor.TryGetValue(adapter.ProviderName.ToLower(), out Func <IDbConnectionLtsAdapter, IDatabaseFor> factory)) { return(DatabaseForCache.GetOrAdd(adapter, factory.Invoke(adapter))); } throw new DException($"不支持的供应商:{adapter.ProviderName}"); }
public Database(IReadOnlyConnectionConfig connectionConfig, IDbConnectionLtsAdapter adapter) { this.connectionConfig = connectionConfig; this.adapter = adapter; this.databaseFor = DbConnectionManager.GetOrCreate(adapter); }
private static ICustomVisitorList GetVisitors(IDbConnectionLtsAdapter adapter) => adapter.Visitors;
private static ISQLCorrectSettings GetSettings(IDbConnectionLtsAdapter adapter) => adapter.Settings;
private static string GetProviderName(IDbConnectionLtsAdapter adapter) => adapter.ProviderName;