DcsvIo.D2.Handler.Repo.Abstractions
0.1.1
dotnet add package DcsvIo.D2.Handler.Repo.Abstractions --version 0.1.1
NuGet\Install-Package DcsvIo.D2.Handler.Repo.Abstractions -Version 0.1.1
<PackageReference Include="DcsvIo.D2.Handler.Repo.Abstractions" Version="0.1.1" />
<PackageVersion Include="DcsvIo.D2.Handler.Repo.Abstractions" Version="0.1.1" />
<PackageReference Include="DcsvIo.D2.Handler.Repo.Abstractions" />
paket add DcsvIo.D2.Handler.Repo.Abstractions --version 0.1.1
#r "nuget: DcsvIo.D2.Handler.Repo.Abstractions, 0.1.1"
#:package DcsvIo.D2.Handler.Repo.Abstractions@0.1.1
#addin nuget:?package=DcsvIo.D2.Handler.Repo.Abstractions&version=0.1.1
#tool nuget:?package=DcsvIo.D2.Handler.Repo.Abstractions&version=0.1.1
DcsvIo.D2.Handler.Repo.Abstractions
Vocabulary for repo-flavored handlers — what app-layer code touches when it needs to discriminate database failures (unique violation, FK violation, deadlock, concurrency conflict, connection failure, etc.). Pure abstractions: zero infrastructure dependencies. EF Core, Npgsql, and any provider knowledge live in sibling packages (DcsvIo.D2.Handler.Repo, DcsvIo.D2.Handler.Repo.Postgres).
Install
dotnet add package DcsvIo.D2.Handler.Repo.Abstractions
Public API
| Type | Role |
|---|---|
DbFailureKind |
Enum — ConcurrencyConflict / UniqueViolation / ForeignKeyViolation / NotNullViolation / CheckViolation / Timeout / Deadlock / ConnectionFailure |
IDbExceptionClassifier |
Provider seam — DbFailureKind? Classify(Exception) |
DbErrorCodes |
String constants (UNIQUE_VIOLATION, FOREIGN_KEY_VIOLATION, etc.) used as D2Result.ErrorCode values |
D2Result DB factories |
Static C# 14 extension factories — D2Result.UniqueViolation(), .ConcurrencyConflict(), .DbDeadlock(), etc. (non-generic + generic) |
| DB booleans | C# 14 instance extension properties — result.IsUniqueViolation, result.IsConcurrencyConflict, result.IsTransientDbFailure, etc. |
Emitting + discriminating DB failures
Handler code returns typed DB failures via the extension factories:
return D2Result<User>.UniqueViolation(
messages: [TK.Auth.Errors.EMAIL_ALREADY_TAKEN],
inputErrors: [new InputError("email", "EMAIL_ALREADY_TAKEN")]);
Caller code discriminates via the boolean discriminators:
var result = await createUser.HandleAsync(input);
if (result.IsUniqueViolation)
return Conflict(result.Messages);
if (result.IsTransientDbFailure)
return await retryPolicy.RetryAsync(() => createUser.HandleAsync(input));
if (result.IsConcurrencyConflict)
return await ReloadAndMergeAsync(input);
The IsTransientDbFailure predicate is a roll-up — IsDbDeadlock || IsDbTimeout || IsDbConnectionFailure. IsConcurrencyConflict is intentionally excluded — concurrency conflicts need reload-then-merge logic, not a blind retry.
IsTransientDbFailure is a separate axis from the built-in IsTransientRetryable (IsServiceUnavailable || IsRateLimited) on D2Result in the result lib. They live in separate libs because not every consumer of D2Result deals with a database; the DB roll-up only loads when the consumer references this package. A generic retry policy that wants to catch BOTH HTTP-flavored AND DB-flavored transient failures should check the union: result.IsTransientRetryable || result.IsTransientDbFailure.
Default messages
Each factory accepts an optional messages parameter; when omitted, the generic fallback from TK.Common.Errors.* is used:
| Factory | Default TKMessage |
|---|---|
ConcurrencyConflict() |
TK.Common.Errors.CONCURRENCY_CONFLICT |
UniqueViolation() |
TK.Common.Errors.UNIQUE_VIOLATION |
ForeignKeyViolation() |
TK.Common.Errors.FOREIGN_KEY_VIOLATION |
NotNullViolation() |
TK.Common.Errors.NOT_NULL_VIOLATION |
CheckViolation() |
TK.Common.Errors.CHECK_VIOLATION |
DbTimeout() |
TK.Common.Errors.DB_TIMEOUT |
DbDeadlock() |
TK.Common.Errors.DB_DEADLOCK |
DbConnectionFailure() |
TK.Common.Errors.DB_CONNECTION_FAILURE |
These defaults are deliberately generic ("This value is already in use"). Handlers that know the constraint identity should override the message — e.g. [TK.Auth.Errors.EMAIL_ALREADY_TAKEN] instead — and attach an InputError so the form UI can highlight the offending field.
Status code mapping
| Factory | HTTP status |
|---|---|
ConcurrencyConflict / UniqueViolation / ForeignKeyViolation / DbDeadlock |
409 Conflict |
NotNullViolation / CheckViolation |
400 Bad Request |
DbTimeout / DbConnectionFailure |
503 Service Unavailable |
Dependencies
DcsvIo.D2.Result— baseD2Resulttype that the factories extendDcsvIo.D2.I18n—TKMessage+TKcodegen entry point
Zero external NuGet packages. No EF Core, no Npgsql.
Related packages
DcsvIo.D2.Handler.Repo—BaseRepoHandlerconsumes the classifier interfaceDcsvIo.D2.Handler.Repo.Postgres— PostgreSQL classifier implementation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- DcsvIo.D2.I18n (>= 0.1.1)
- DcsvIo.D2.Result (>= 0.1.1)
- dotenv.net (>= 4.0.2)
- JetBrains.Annotations (>= 2025.2.4)
- Microsoft.Extensions.Configuration (>= 10.0.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on DcsvIo.D2.Handler.Repo.Abstractions:
| Package | Downloads |
|---|---|
|
DcsvIo.D2.Handler.Repo.Postgres
PostgreSQL IDbExceptionClassifier implementation for D2, plugging Npgsql failure classification into BaseRepoHandler. |
|
|
DcsvIo.D2.Handler.Repo
EF-flavored BaseRepoHandler for D2 — converts database exceptions captured during execution into typed D2Result failures. |
GitHub repositories
This package is not used by any popular GitHub repositories.