Bring SQL-like transaction behavior to C# actions. ActionTransaction adds savepoints, rollbacks, and commit support to your method flows—ensuring consistency even in complex logic chains.
$ dotnet add package DCTekSolutions.ActionTransactionActionTransaction brings SQL-style transaction control to regular C# code.
Use savepoints, commits, and rollbacks to manage complex logic safely and predictably.
Free to use for personal and commercial projects. This package is closed source.
ITransactionalActionpublic class StepOne : ITransactionalAction
{
public Task ExecuteAsync()
{
Console.WriteLine("Step 1 executed");
return Task.CompletedTask;
}
public Task RollbackAsync()
{
Console.WriteLine("Step 1 rolled back");
return Task.CompletedTask;
}
}
var orchestrator = new TransactionalOrchestrator(logger);
orchestrator.AddAction(new StepOne());
orchestrator.AddAction(new StepTwo()); // Another ITransactionalAction
await orchestrator.CommitAsync();
orchestrator.AddAction(new StepOne());
orchestrator.CreateSavepoint("AfterStep1");
orchestrator.AddAction(new RiskyAction());
await orchestrator.CommitAsync();
try
{
orchestrator.AddAction(new SetupAction());
orchestrator.CreateSavepoint("BeforeDanger");
orchestrator.AddAction(new FailingAction());
await orchestrator.CommitAsync();
}
catch
{
await orchestrator.RollbackToSavepointAsync("BeforeDanger");
}
await orchestrator.ClearAsync();
Use ClearAsync() to fully reset the orchestrator between transactions, especially in shared lifetime scenarios.
You can register the orchestrator in your Startup.cs:
services.AddActionTransaction(ServiceLifetime.Scoped);
Or use the default:
services.AddActionTransaction(); // Defaults to Transient
| Method | Purpose |
|---|---|
AddAction(ITransactionalAction) | Adds an action to be part of the transaction |
CreateSavepoint(string name) | Marks a rollback point |
RollbackToSavepointAsync(string name) | Rolls back to a specific savepoint |
CommitAsync() | Executes all actions in order |
ClearAsync() | Resets the orchestrator's state |
ActionTransaction by DC Tek Solutions is currently free, and user support keeps it that way!
If you find it helpful, please consider supporting future development:
Thank you for your support!