Refactoring SetupConsole with DBFactory
This commit is contained in:
parent
8dd01d291d
commit
78d49a9829
20 changed files with 337 additions and 407 deletions
|
|
@ -3,7 +3,7 @@ using Npgsql;
|
|||
using System.Data;
|
||||
namespace PlanTempus.Database.ModuleRegistry
|
||||
{
|
||||
|
||||
|
||||
public class DbPostgreSqlModule : Module
|
||||
{
|
||||
public required string ConnectionString { get; set; }
|
||||
|
|
@ -12,42 +12,14 @@ namespace PlanTempus.Database.ModuleRegistry
|
|||
{
|
||||
Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider();
|
||||
|
||||
builder.Register<Core.ConnectionFactory.IDbConnectionFactory>(c =>
|
||||
new Core.ConnectionFactory.PostgresConnectionFactory(ConnectionString))
|
||||
.SingleInstance();
|
||||
builder.RegisterType<Core.ConnectionFactory.PostgresConnectionFactory>()
|
||||
.As<Core.ConnectionFactory.IDbConnectionFactory>()
|
||||
.WithParameter(new TypedParameter(typeof(string), ConnectionString))
|
||||
.SingleInstance();
|
||||
|
||||
builder.RegisterType<Core.Sql.SqlOperations>()
|
||||
.As<Core.Sql.IDatabaseOperations>();
|
||||
}
|
||||
}
|
||||
public class PostgresConnectionFactory1 //: IDbConnectionFactory
|
||||
{
|
||||
private readonly string _baseConnectionString;
|
||||
|
||||
public PostgresConnectionFactory1(string connectionString)
|
||||
{
|
||||
_baseConnectionString = connectionString;
|
||||
}
|
||||
|
||||
public IDbConnection Create()
|
||||
{
|
||||
return new NpgsqlConnection(_baseConnectionString);
|
||||
}
|
||||
|
||||
public IDbConnection Create(string username, string password)
|
||||
{
|
||||
var builder = new NpgsqlConnectionStringBuilder(_baseConnectionString)
|
||||
{
|
||||
Username = username,
|
||||
Password = password
|
||||
};
|
||||
|
||||
return new NpgsqlConnection(builder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue