TxCommand 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TxCommand --version 0.1.0                
NuGet\Install-Package TxCommand -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TxCommand" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TxCommand --version 0.1.0                
#r "nuget: TxCommand, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.2.0 1,240 3/5/2023
1.1.0 4,885 2/8/2022
1.0.1 731 12/9/2021
1.0.0 1,672 9/1/2021
0.5.0 377 7/2/2021
0.4.0 360 7/2/2021
0.3.1 1,238 4/18/2021
0.3.0 349 4/18/2021
0.1.0 440 3/10/2021