/// <summary> /// Creates a new <see cref="IDbConnection"/> for given connection key.</summary> /// <param name="connectionKey">Connection key</param> /// <returns>A new <see cref="IDbConnection"/> object.</returns> public virtual IDbConnection NewByKey(string connectionKey) { var info = connectionStrings.TryGetConnectionString(connectionKey); if (info == null) { throw new InvalidOperationException(string.Format("No connection string with key {0} in configuration file!", connectionKey)); } return(New(info.ConnectionString, info.ProviderName, info.Dialect)); }
/// <summary> /// Gets connection string by key /// </summary> /// <param name="connectionStrings">Connection strings object</param> /// <param name="connectionKey">Connection key</param> /// <returns>Connection string with key, or throws an ArgumentOutOfRangeException</returns> public static IConnectionString Get(this IConnectionStrings connectionStrings, string connectionKey) { if (connectionStrings == null) { throw new ArgumentNullException(nameof(connectionStrings)); } var connectionString = connectionStrings.TryGetConnectionString(connectionKey); if (connectionString == null) { throw new ArgumentOutOfRangeException(nameof(connectionKey)); } return(connectionString); }