40 lines
1.4 KiB
C#
40 lines
1.4 KiB
C#
|
// <copyright file="TransactionProvider.cs" company="alveus.dev">
|
||
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
||
|
// </copyright>
|
||
|
|
||
|
using System.Data;
|
||
|
using Astral.Core.Infrastructure;
|
||
|
using Injectio.Attributes;
|
||
|
|
||
|
namespace Astral.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="ITransactionProvider" />
|
||
|
public IDbTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
|
||
|
{
|
||
|
var connection = _dbConnectionProvider.OpenConnection();
|
||
|
return connection.BeginTransaction(isolationLevel);
|
||
|
}
|
||
|
|
||
|
/// <inheritdoc cref="ITransactionProvider" />
|
||
|
public async Task<IDbTransaction> BeginTransactionAsync(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
|
||
|
{
|
||
|
var connection = await _dbConnectionProvider.OpenConnectionAsync();
|
||
|
return connection.BeginTransaction(isolationLevel);
|
||
|
}
|
||
|
}
|