DcsvIo.D2.Handler.Abstractions 0.2.20

dotnet add package DcsvIo.D2.Handler.Abstractions --version 0.2.20
                    
NuGet\Install-Package DcsvIo.D2.Handler.Abstractions -Version 0.2.20
                    
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="DcsvIo.D2.Handler.Abstractions" Version="0.2.20" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DcsvIo.D2.Handler.Abstractions" Version="0.2.20" />
                    
Directory.Packages.props
<PackageReference Include="DcsvIo.D2.Handler.Abstractions" />
                    
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 DcsvIo.D2.Handler.Abstractions --version 0.2.20
                    
#r "nuget: DcsvIo.D2.Handler.Abstractions, 0.2.20"
                    
#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 DcsvIo.D2.Handler.Abstractions@0.2.20
                    
#: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=DcsvIo.D2.Handler.Abstractions&version=0.2.20
                    
Install as a Cake Addin
#tool nuget:?package=DcsvIo.D2.Handler.Abstractions&version=0.2.20
                    
Install as a Cake Tool

DcsvIo.D2.Handler.Abstractions

Domain-safe slice of the handler stack: IHandler<in TInput, TOutput>, IHandlerContext, HandlerOptions. Domain code references this package. The runtime types (BaseHandler, HandlerContext, HandlerTelemetry, AddD2Handler) are in DcsvIo.D2.Handler.

Install

dotnet add package DcsvIo.D2.Handler.Abstractions

Public surface

public interface IHandler<in TInput, TOutput>
    where TInput : notnull
{
    ValueTask<D2Result<TOutput?>> HandleAsync(
        TInput input,
        CancellationToken ct = default,
        HandlerOptions? options = null);
}

public interface IHandlerContext
{
    IRequestContext Request { get; }
    ILogger Logger { get; }
}

public sealed record HandlerOptions
{
    public bool LogInput { get; init; } = true;
    public bool LogOutput { get; init; } = true;
    public TimeSpan? SlowThreshold { get; init; } = TimeSpan.FromMilliseconds(100);
    public TimeSpan? CriticalThreshold { get; init; } = TimeSpan.FromMilliseconds(500);
    public ScopeRequirement? ScopeRequirement { get; init; }
    /// <summary>
    /// Composition scopes elevated for the ExecuteAsync window after Require passes.
    /// Null/empty disables elevation; the lease removes what it added. A non-empty
    /// value requires a non-empty ScopeRequirement or the pipeline answers Forbidden.
    /// </summary>
    public IReadOnlySet<string>? ElevateScopes { get; init; }
}

/// <summary>Declares the per-handler scope requirement.</summary>
public sealed record ScopeRequirement(HandlerScopeMatch Match, IReadOnlySet<string> Scopes);

public enum HandlerScopeMatch { Any, All }

public enum D2HandlerScopeMode { Any, All, InfraExempt }

[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class D2GeneratedHandlerScopeAttribute(D2HandlerScopeMode mode) : Attribute
{
    public D2HandlerScopeMode Mode { get; }
}

TInput : notnull means the whole input is never a nullable type argument (string?, OrderInput?). Optional or absent values are members of the non-null input type. A null input at runtime still fails closed as ValidationFailed in BaseHandler.

ScopeRequirement combines an explicit match mode with the scope set: Match is HandlerScopeMatch.Any (caller must hold at least one of the scopes) or HandlerScopeMatch.All (caller must hold every scope). A null HandlerOptions.ScopeRequirement disables the per-handler pre-check entirely. The ScopeRequirement constructor throws ArgumentException for an empty Scopes set, and the pipeline guard is { Scopes.Count: > 0 } also skips the check for a requirement that has no scopes. HandlerScopeMatch is declared in this assembly. Handlers never take a compile-time dependency on DcsvIo.D2.Auth.Abstractions (layer-hygiene invariant).

D2GeneratedHandlerScopeAttribute marks a handler class whose scope binding is declared in a generated Scope partial and not by a hand-written DefaultOptions override. A consumer does not write it by hand: the scope generator stamps it, and HandlerScopeAnalyzer in DcsvIo.D2.Handler.Analyzers reads it as proof that the class bound its requirement, so that analyzer skips a generated partial's AST. Mode is a D2HandlerScopeMode, the closed set of bindings the generator can stamp: Any (the caller holds at least one declared scope), All (the caller holds every declared scope), and InfraExempt (an infrastructure operation that declares no scope requirement at all). A consumer reads Mode to see which of those bindings a generated handler took.

JWT signature, expiry, audience and fingerprint-binding validation are not per-handler. Auth middleware (HTTP, gRPC, AMQP) performs them at the transport level before the handler runs. Per-handler scope requirements (ScopeRequirement) are here because they vary by operation. Audience and signature are per-service constants, and putting them on HandlerOptions would let each handler set them. See the HandlerOptions remarks.


Why split from DcsvIo.D2.Handler?

Domain code (entities, value objects and domain services) should not depend on Microsoft.Extensions.DependencyInjection, OpenTelemetry, or any infrastructure package. The split lets domain projects reference only this package, and use IHandler for handler-shaped domain services. The concrete handler and the DI extension are in the sibling package DcsvIo.D2.Handler.


Dependencies

  • DcsvIo.D2.Result - D2Result<T> return type
  • DcsvIo.D2.Context.Abstractions - IRequestContext on the context
  • Microsoft.Extensions.Logging.Abstractions - ILogger on the context

  • DcsvIo.D2.Handler - concrete BaseHandler + HandlerContext + DI extension
  • DcsvIo.D2.Handler.Repo - handler for Entity Framework Core that maps PostgreSQL and EF exceptions to D2Result failure codes

Recommended layout: one handler folder per operation (Application/Handlers/{Commands,Queries}/<Op>/).

Product 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. 
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 DcsvIo.D2.Handler.Abstractions:

Package Downloads
DcsvIo.D2.Handler

BaseHandler for D2 - the abstract base every handler inherits, providing scope pre-checks, OpenTelemetry activity and metrics, log scope, and a universal try/catch.

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.

Version Downloads Last Updated
0.2.20 160 10/26/2026
0.1.1 190 7/17/2026
0.1.0 183 7/17/2026