FruityFoundation/FruityFoundation.DataAccess.Sqlite/DbConnectionFactory.cs
2024-06-23 18:25:03 -04:00

34 lines
1.1 KiB
C#

using FruityFoundation.DataAccess.Abstractions;
namespace FruityFoundation.DataAccess.Sqlite;
public class DbConnectionFactory : IDbConnectionFactory
{
private readonly string _readWriteConnectionString;
private readonly string _readOnlyConnectionString;
public DbConnectionFactory(string readWriteConnectionString, string readOnlyConnectionString)
{
_readWriteConnectionString = readWriteConnectionString;
_readOnlyConnectionString = readOnlyConnectionString;
}
public INonTransactionalDbConnection<ReadWrite> CreateConnection()
{
if (string.IsNullOrWhiteSpace(_readWriteConnectionString))
throw new ApplicationException("ReadWrite connection string cannot be null or empty.");
var connection = new NonTransactionalDbConnection<ReadWrite>(_readWriteConnectionString);
return connection;
}
public INonTransactionalDbConnection<ReadOnly> CreateReadOnlyConnection()
{
if (string.IsNullOrWhiteSpace(_readOnlyConnectionString))
throw new ApplicationException("ReadOnly connection string cannot be null or empty.");
var connection = new NonTransactionalDbConnection<ReadOnly>(_readOnlyConnectionString);
return connection;
}
}