Table of Contents

Class UnitOfWork

Namespace
Excalibur.Data
Assembly
Excalibur.Data.Abstractions.dll

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

connection IDbConnection

The 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

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A Task representing the asynchronous operation.

CommitAsync(CancellationToken)

Commits the active transaction.

public Task CommitAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A Task representing the asynchronous operation.

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

cancellationToken CancellationToken

The cancellation token for the operation.

Returns

Task

A Task representing the asynchronous operation.