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
<PackageReference Include="DAMA.Software.MySqlUnitOfWork" Version="2.0.0" />
<PackageVersion Include="DAMA.Software.MySqlUnitOfWork" Version="2.0.0" />
<PackageReference Include="DAMA.Software.MySqlUnitOfWork" />
paket add DAMA.Software.MySqlUnitOfWork --version 2.0.0
#r "nuget: DAMA.Software.MySqlUnitOfWork, 2.0.0"
#:package DAMA.Software.MySqlUnitOfWork@2.0.0
#addin nuget:?package=DAMA.Software.MySqlUnitOfWork&version=2.0.0
#tool nuget:?package=DAMA.Software.MySqlUnitOfWork&version=2.0.0
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 ofMySqlTransaction.ITransactionScope— anITransactionContextthat is alsoIAsyncDisposableand exposesCommitAsync(). Disposing without committing rolls the transaction back.IUnitOfWork.BeginAsync()— opens the scoped connection (viaMySQLRetryPolicy.EnsureOpenAsync) and starts a transaction, returning anITransactionScope.MySqlUnitOfWork— the MySQL implementation, constructed from the request-scopedMySqlConnection.MySqlTransactionContextAccessor.Unwrap(context)— used inside concrete MySQL DAOs to recover the underlyingMySqlTransaction.IUnitOfWork.RunInTransactionAsync(...)— extension overloads that wrapBeginAsync/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 | Versions 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. |
-
net9.0
- JuanCarlosHS.SQLDaosPackage (>= 3.1.0)
- MySql.Data (>= 9.3.0)
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.