Shuttle.Core.Transactions
PM> Install-Package Shuttle.Core.Transactions
This package makes use of the .Net TransactionScope
class to provide ambient transaction handling.
Configuration
The relevant components may be configured using IServiceColletion
:
services.AddTransactionScope(builder =>
{
builder.Options.Enabled = true;
builder.Options.IsolationLevel = isolationLevel;
builder.Options.Timeout = TimeSpan.FromSeconds(30);
});
The default JSON settings structure is as follows::
{
"Shuttle": {
"TransactionScope": {
"Enabled": true,
"IsolationLevel": "isolation-level",
"Timeout": "00:00:30"
}
}
}
ITransactionScope
An implementation of the ITransactionScope
interface is used to wrap a TransactionScope
.
The DefaultTransactionScope
makes use of the standard .NET TransactionScope
functionality. There is also a NullTransactionScope
that implements the null pattern so it implements the interface but does not do anything.
Properties
Guid Id { get; }
Returns the Id of the transaction scope.
Methods
void Complete();
Marks the transaction scope as complete.
ITransactionScopeFactory
An implementation of the ITransactionScopeFactory
interface provides instances of an ITransactionScope
implementation.
The TransactionScopeFactory
provides a DefaultTransactionScope
instance if transaction scopes are Enabled
; else a NullTransactionScope
that implements the null pattern.
Create
ITransactionScope Create(IsolationLevel isolationLevel, TimeSpan timeout);
Creates the relevant instance using the given parameters.