Interface IPersistenceProviderTransaction
- Namespace
- Excalibur.Data.Persistence
- Assembly
- Excalibur.Data.Abstractions.dll
Provides transaction coordination capabilities for persistence providers.
Obtain via GetService(Type) with
typeof(IPersistenceProviderTransaction).
public interface IPersistenceProviderTransaction
Remarks
This interface follows the ISP pattern — consumers that only need simple data request execution use IPersistenceProvider directly. Transaction-heavy workflows use this sub-interface. Connection details and the retry policy are a separate capability, IPersistenceProviderConnection, because a provider can supply those without being able to run a transaction.
Reference: System.Data.IDbConnection.BeginTransaction — transaction creation is
a separate concern from connection/query execution.
Offer this capability only if you can honour it. The scope returned by CreateTransactionScope(IsolationLevel, TimeSpan?) is ambient and open-ended: it is created before the provider knows which requests will enrol in it, and those requests are then executed against it. A store whose atomicity requires the full write set up front, a fixed partition key, or a retryable callback cannot express that contract, and should decline this capability by returning null from GetService(Type) rather than throwing here. Declining is visible at discovery, where a caller can still choose another path; throwing is only visible at the point of use, after the caller has committed to a design that cannot work.
Methods
CreateTransactionScope(IsolationLevel, TimeSpan?)
Creates a new transaction scope for coordinating operations across multiple DataRequests.
ITransactionScope CreateTransactionScope(IsolationLevel isolationLevel = IsolationLevel.ReadCommitted, TimeSpan? timeout = null)
Parameters
isolationLevelIsolationLevelThe transaction isolation level.
timeoutTimeSpan?The transaction timeout.
Returns
- ITransactionScope
A new transaction scope.
ExecuteInTransactionAsync<TConnection, TResult>(IDataRequest<TConnection, TResult>, ITransactionScope, CancellationToken)
Executes a DataRequest within a transaction scope with retry logic.
Task<TResult> ExecuteInTransactionAsync<TConnection, TResult>(IDataRequest<TConnection, TResult> request, ITransactionScope transactionScope, CancellationToken cancellationToken) where TConnection : IDisposable
Parameters
requestIDataRequest<TConnection, TResult>The data request to execute.
transactionScopeITransactionScopeThe transaction scope to use.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TResult>
The result of the data request execution.
Type Parameters
TConnectionThe type of the database connection.
TResultThe type of the result.