Table of Contents

Interface IUnitOfWork

Namespace
FishMMO.Database.Npgsql.Services.Interfaces
Assembly
FishMMO-DB.dll

Represents a unit of work for coordinating multiple service calls into a single database transaction.

public interface IUnitOfWork : IDisposable, IAsyncDisposable
Inherited Members

Remarks

A unit of work creates a shared NpgsqlDbContext and an explicit database transaction. Services invoked within the unit of work reuse the ambient context and do not commit independently. The transaction is finalized only when CommitAsync(CancellationToken) or RollbackAsync(CancellationToken) is called.

Properties

DisposeFault

The failure from an implicit rollback performed during disposal, or null when disposal completed cleanly or the work was already committed or rolled back.

DatabaseResult? DisposeFault { get; }

Property Value

DatabaseResult?

Remarks

Disposal is the one path in this layer with no return value to report through, and this project deliberately has no logger to fall back on. A using block that returns early without committing therefore discarded its transaction silently, and a rollback that itself failed — leaving the transaction to be reaped server-side — discarded the reason too. Recording it here keeps it recoverable: check it after the scope ends when the distinction matters.

Methods

CommitAsync(CancellationToken)

Persists any tracked EF Core changes and commits the underlying transaction.

Task<DatabaseResult> CommitAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<DatabaseResult>

RollbackAsync(CancellationToken)

Rolls back the underlying transaction.

Task<DatabaseResult> RollbackAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<DatabaseResult>