DAMA.Software.MySqlUnitOfWork 2.0.0

dotnet add package DAMA.Software.MySqlUnitOfWork --version 2.0.0
                    
NuGet\Install-Package DAMA.Software.MySqlUnitOfWork -Version 2.0.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="DAMA.Software.MySqlUnitOfWork" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DAMA.Software.MySqlUnitOfWork" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DAMA.Software.MySqlUnitOfWork" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DAMA.Software.MySqlUnitOfWork --version 2.0.0
                    
#r "nuget: DAMA.Software.MySqlUnitOfWork, 2.0.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.
#:package DAMA.Software.MySqlUnitOfWork@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DAMA.Software.MySqlUnitOfWork&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DAMA.Software.MySqlUnitOfWork&version=2.0.0
                    
Install as a Cake Tool

DAMA.Software.MySqlUnitOfWork

Unit-of-work abstraction over a scoped MySQL connection for the DAMA backend services. Extracted so that service-layer code and DAO interfaces never reference MySql.Data types: the transaction is handed around as an opaque ITransactionContext and only the concrete (MySQL) DAOs unwrap it.

What it provides

  • ITransactionContext — opaque handle that DAO methods accept instead of MySqlTransaction.
  • ITransactionScope — an ITransactionContext that is also IAsyncDisposable and exposes CommitAsync(). Disposing without committing rolls the transaction back.
  • IUnitOfWork.BeginAsync() — opens the scoped connection (via MySQLRetryPolicy.EnsureOpenAsync) and starts a transaction, returning an ITransactionScope.
  • MySqlUnitOfWork — the MySQL implementation, constructed from the request-scoped MySqlConnection.
  • MySqlTransactionContextAccessor.Unwrap(context) — used inside concrete MySQL DAOs to recover the underlying MySqlTransaction.
  • IUnitOfWork.RunInTransactionAsync(...) — extension overloads that wrap BeginAsync/CommitAsync: one returns (TResult Result, bool ShouldCommit) so the work can ask for a rollback without throwing, the other always commits.

Why it exists

Before this package, services injected MySqlConnection directly, called BeginTransactionAsync()/CommitAsync() by hand, and DAO interfaces took a MySqlTransaction parameter. That tied the business layer to MySQL and made unit testing awkward. This package owns the transaction lifecycle so the business layer depends only on IUnitOfWork / ITransactionContext.

Usage

Register in Program.cs:

builder.Services.AddScoped<IUnitOfWork, MySqlUnitOfWork>();

In a service:

await using ITransactionScope scope = await unitOfWork.BeginAsync();
bool created = await userDao.TryCreateAsync(user, scope);
if (!created)
{
    return null;
}
await tenantDomainDao.CreateAsync(tenantDomain, scope);
await scope.CommitAsync();

In a concrete MySQL DAO:

public async Task CreateAsync(TenantDomain domain, ITransactionContext transaction)
{
    MySqlTransaction tx = MySqlTransactionContextAccessor.Unwrap(transaction);
    MySqlCommand command = new MySqlCommand(sql, _connection, tx);
    ...
}

License

MIT.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DAMA.Software.MySqlUnitOfWork:

Package Downloads
DAMA.Software.MySqlOutbox

Lease + failure-recording helpers for the transactional Outbox pattern on MySQL. Shared between DAMA backend services that publish events via outbox tables.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 161 5/28/2026
1.1.0 141 5/20/2026
1.0.0 88 5/19/2026