TxCommand 0.1.0
See the version list below for details.
dotnet add package TxCommand --version 0.1.0
NuGet\Install-Package TxCommand -Version 0.1.0
<PackageReference Include="TxCommand" Version="0.1.0" />
paket add TxCommand --version 0.1.0
#r "nuget: TxCommand, 0.1.0"
// Install TxCommand as a Cake Addin #addin nuget:?package=TxCommand&version=0.1.0 // Install TxCommand as a Cake Tool #tool nuget:?package=TxCommand&version=0.1.0
TxCommand
A simple commanding library with support for executing commands within a database transaction.
Usage
Commands are executed with a CommandExecutor, which provides a database transaction. CommandExecutors are a single use object and should be used for a specific set of operations.
Below is an example of how to use the command executors in a service.
public class PetService
{
private readonly ITxCommandExecutorFactory _commandExecutorFactory;
public PetService(ITxCommandExecutorFactory commandExecutorFactory)
{
_commandExecutorFactory = commandExecutorFactory;
}
// Adds a collection of pets, if any of them fail, the
// transaction will be rolled back.
public async Task AddPets(int personId, string[] pets)
{
// The executor commits the transaction on disposal.
using (var executor = _commandExecutorFactory.Create())
{
foreach (var pet in pets)
{
var command = new AddPetCommand(personId, pet);
await executor.ExecuteAsync(command);
}
}
}
}
Here is an example of a transient service, CreatePersonService
. This should be initialised on a per-use basis, as it has a command executor as a dependency.
public class CreatePersonService : IDisposable
{
private readonly ITxCommandExecutor _executor;
public CreatePersonService(ITxCommandExecutor executor)
{
_executor = executor;
}
// Creates a new Person, then adds a Pet. If either command throws
// an exception, the transaction will be rolled back.
public async Task<int> Create(string personName, string petName)
{
var createPersonCommand = new CreatePersonCommand(personName);
var personId = await _executor.ExecuteAsync(createPersonCommand);
var addPetCommand = new AddPetCommand(personId, petName);
await _executor.ExecuteAsync(addPetCommand);
return personId;
}
public void Dispose()
{
// On disposal, the executor is disposed, which commits the transaction.
_executor?.Dispose();
}
}
Dependency Injection
If you're using Microsoft.Extensions.DependencyInjection
for dependency injection, AddTxCommand()
can be called on a IServiceCollection
.
var services = new ServiceCollection()
.AddTxCommand()
.BuildServiceProvider();
var factory = services.GetRequiredService<ITxCommandExecutorFactory>();
var executor = services.GetRequiredService<ITxCommandExecutor>();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- TxCommand.Abstractions (>= 0.1.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TxCommand:
Package | Downloads |
---|---|
TxCommand.Sql
Provides SQL implementations for TxCommand, supporting MySQL and SQL Server. |
|
TxCommand.Mongo
An implementation of TxCommand to provide transactional commanding interfaces for MongoDB. |
GitHub repositories
This package is not used by any popular GitHub repositories.