galaeth-draft/Galaeth.DAL/Infrastructure/TransactionProvider.cs
2024-11-17 09:31:01 +00:00

36 lines
1.3 KiB
C#

using System.Data;
using Galaeth.Core.Infrastructure;
using Injectio.Attributes;
namespace Galaeth.DAL.Infrastructure;
/// <inheritdoc />
[RegisterScoped]
public class TransactionProvider : ITransactionProvider
{
private readonly IDbConnectionProvider _dbConnectionProvider;
/// <summary>
/// Initializes a new instance of the <see cref="TransactionProvider"/> class.
/// </summary>
/// <param name="dbConnectionProvider">Instance of <see cref="IDbConnectionProvider"/>.</param>
public TransactionProvider(IDbConnectionProvider dbConnectionProvider)
{
_dbConnectionProvider = dbConnectionProvider;
}
/// <inheritdoc cref="Galaeth.Core.Infrastructure.ITransactionProvider"/>
public IDbTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
{
var connection = _dbConnectionProvider.OpenConnection();
return connection.BeginTransaction(isolationLevel);
}
/// <inheritdoc cref="Galaeth.Core.Infrastructure.ITransactionProvider"/>
public async Task<IDbTransaction> BeginTransactionAsync(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
{
var connection = await _dbConnectionProvider.OpenConnectionAsync();
return connection.BeginTransaction(isolationLevel);
}
}