Class UnitOfWork
Provides a simple implementation of IUnitOfWork using an IDbConnection.
public sealed class UnitOfWork : IUnitOfWork, IAsyncDisposable
- Inheritance
-
UnitOfWork
- Implements
- Inherited Members
Constructors
UnitOfWork(IDbConnection)
Initializes a new instance of the UnitOfWork class.
public UnitOfWork(IDbConnection connection)
Parameters
connectionIDbConnectionThe database connection to manage.
Properties
Connection
Gets the underlying database connection.
public IDbConnection Connection { get; }
Property Value
- IDbConnection
The underlying database connection.
Transaction
Gets the current database transaction if one has been started.
public IDbTransaction? Transaction { get; }
Property Value
- IDbTransaction
The current database transaction if one has been started.
Methods
BeginTransactionAsync(CancellationToken)
Begins a new transaction on the connection.
public Task BeginTransactionAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
CommitAsync(CancellationToken)
Commits the active transaction.
public Task CommitAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
RollbackAsync(CancellationToken)
Rolls back the active transaction.
public Task RollbackAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.