FruityFoundation/FruityFoundation.DataAccess.Core/DbConnectionFactory.cs
2024-06-23 22:27:05 -04:00

31 lines
1.0 KiB
C#

using System.Data.Common;
using FruityFoundation.DataAccess.Abstractions;
namespace FruityFoundation.DataAccess.Core;
public class DbConnectionFactory : IDbConnectionFactory
{
private readonly Func<DbConnection> _readWriteConnectionFactory;
private readonly Func<DbConnection> _readOnlyConnectionFactory;
public DbConnectionFactory(Func<DbConnection> readWriteConnectionFactory, Func<DbConnection> readOnlyConnectionFactory)
{
_readWriteConnectionFactory = readWriteConnectionFactory;
_readOnlyConnectionFactory = readOnlyConnectionFactory;
}
public INonTransactionalDbConnection<ReadWrite> CreateConnection()
{
var connection = _readWriteConnectionFactory();
var nonTxConnection = new NonTransactionalDbConnection<ReadWrite>(connection);
return nonTxConnection;
}
public INonTransactionalDbConnection<ReadOnly> CreateReadOnlyConnection()
{
var connection = _readOnlyConnectionFactory();
var nonTxConnection = new NonTransactionalDbConnection<ReadOnly>(connection);
return nonTxConnection;
}
}