FruityFoundation/FruityFoundation.DataAccess.Sqlite/DbConnectionFactory.cs

34 lines
1.1 KiB
C#
Raw Normal View History

2024-06-23 18:15:32 -04:00
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))
2024-06-23 18:25:03 -04:00
throw new ApplicationException("ReadWrite connection string cannot be null or empty.");
2024-06-23 18:15:32 -04:00
var connection = new NonTransactionalDbConnection<ReadWrite>(_readWriteConnectionString);
return connection;
}
public INonTransactionalDbConnection<ReadOnly> CreateReadOnlyConnection()
{
if (string.IsNullOrWhiteSpace(_readOnlyConnectionString))
2024-06-23 18:25:03 -04:00
throw new ApplicationException("ReadOnly connection string cannot be null or empty.");
2024-06-23 18:15:32 -04:00
var connection = new NonTransactionalDbConnection<ReadOnly>(_readOnlyConnectionString);
return connection;
}
}