Skip to content
This repository has been archived by the owner on Dec 23, 2017. It is now read-only.

Commit

Permalink
Update DatabaseManager.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovan Crone committed May 14, 2015
1 parent e43d069 commit 7e35773
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions src/Susanoo.Core/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class DatabaseManager : IDatabaseManager, IDisposable
{
private DbConnection _connection;
private bool _explicitlyOpened;
private readonly string _connectionString;
private string _connectionString;
private readonly Action<DbCommand> _providerSpecificCommandSettings;

/// <summary>
Expand Down Expand Up @@ -70,6 +70,70 @@ public DatabaseManager(string connectionStringName)
throw new ArgumentException("Provider is a required component of the connection string.",
"connectionStringName");
}

protected DatabaseManager()
{

}

public static DatabaseManager CreateFromConnectionStringName(string connectionStringName)
{
var manager = new DatabaseManager();

manager._connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

manager.Provider =
DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName);

if (manager.Provider == null)
throw new ArgumentException("Provider is a required component of the connection string.",
"connectionStringName");

return manager;
}

public static DatabaseManager CreateFromConnectionStringName(DbProviderFactory provider, string connectionStringName)
{
var manager = new DatabaseManager();
manager.Provider = provider;

manager._connectionString = ConfigurationManager.ConnectionStrings[connectionStringName]
.ConnectionString;

return manager;
}

public static DatabaseManager CreateFromConnectionStringName(string connectionStringName, string providerName)
{
var manager = new DatabaseManager();
manager.Provider =
DbProviderFactories.GetFactory(providerName);

if (manager.Provider == null)
throw new ArgumentException("Provider is a required component of the connection string.",
"providerName");

manager._connectionString = ConfigurationManager.ConnectionStrings[connectionStringName]
.ConnectionString;

return manager;
}

public static DatabaseManager CreateFromConnectionString(string connectionString, string providerName)
{
var manager = new DatabaseManager();

manager._connectionString = connectionString;

manager.Provider =
DbProviderFactories.GetFactory(providerName);

if (manager.Provider == null)
throw new ArgumentException("Provider is a required component of the connection string.",
"providerName");

return manager;
}

/// <summary>
/// Gets the connection.
Expand Down Expand Up @@ -541,4 +605,4 @@ public async Task<T> ExecuteScalarAsync<T>(string commandText,
}

#endif
}
}

0 comments on commit 7e35773

Please sign in to comment.