JAAvila.FluentOperations.Grpc
1.5.0
dotnet add package JAAvila.FluentOperations.Grpc --version 1.5.0
NuGet\Install-Package JAAvila.FluentOperations.Grpc -Version 1.5.0
<PackageReference Include="JAAvila.FluentOperations.Grpc" Version="1.5.0" />
<PackageVersion Include="JAAvila.FluentOperations.Grpc" Version="1.5.0" />
<PackageReference Include="JAAvila.FluentOperations.Grpc" />
paket add JAAvila.FluentOperations.Grpc --version 1.5.0
#r "nuget: JAAvila.FluentOperations.Grpc, 1.5.0"
#:package JAAvila.FluentOperations.Grpc@1.5.0
#addin nuget:?package=JAAvila.FluentOperations.Grpc&version=1.5.0
#tool nuget:?package=JAAvila.FluentOperations.Grpc&version=1.5.0
JAAvila.FluentOperations.Grpc
gRPC server interceptor integration for JAAvila.FluentOperations Quality Blueprints. Provides automatic request validation with structured error metadata in gRPC trailers.
Installation
dotnet add package JAAvila.FluentOperations.Grpc
Usage
1. Define a Quality Blueprint
public class CreateOrderBlueprint : QualityBlueprint<CreateOrderRequest>
{
public CreateOrderBlueprint()
{
using (Define())
{
For(x => x.ProductId).Test().NotBeNull().NotBeEmpty();
For(x => x.Quantity).Test().BePositive();
}
}
}
2. Register services
// Program.cs
builder.Services.AddSingleton<CreateOrderBlueprint>();
builder.Services.AddSingleton<IBlueprintValidator>(sp =>
sp.GetRequiredService<CreateOrderBlueprint>());
// Register the interceptor (with optional configuration)
builder.Services.AddGrpcBlueprintValidation(options =>
{
options.FailureStatusCode = StatusCode.InvalidArgument;
options.IncludeReportInTrailers = true;
options.StreamValidation = StreamValidationMode.FirstMessageOnly;
});
// Enable the interceptor on all gRPC services
builder.Services.AddGrpc(options =>
{
options.Interceptors.Add<GrpcBlueprintInterceptor>();
});
3. Validation behavior
When a request fails validation, the interceptor throws an RpcException with:
- Status code: configured via
FailureStatusCode(default:InvalidArgument) - Status message:
"Validation failed with N error(s)." - Metadata entries: one
validation-error-{propertyname}entry per Error-level failure message - Binary trailer (
validation-errors-bin): JSON-serialized error dictionary (whenIncludeReportInTrailers = true)
Only Severity.Error failures block the call. Warning and Info failures are not included in error metadata.
Streaming modes
The StreamValidation option controls validation on client-streaming and duplex-streaming calls:
| Mode | Behavior |
|---|---|
FirstMessageOnly (default) |
Validates only the first message; subsequent messages pass through |
EveryMessage |
Validates every message on the stream |
Skip |
No validation for streaming calls |
Server-streaming calls validate the single request message the same way as unary calls.
Example client error handling
try
{
await client.CreateOrderAsync(request);
}
catch (RpcException ex) when (ex.StatusCode == StatusCode.InvalidArgument)
{
// Read per-property errors from metadata
var productErrors = ex.Trailers.GetAll("validation-error-productid");
// Or read the full JSON dictionary from the binary trailer
var entry = ex.Trailers.Get("validation-errors-bin");
if (entry is not null)
{
var errors = JsonSerializer.Deserialize<Dictionary<string, string[]>>(entry.ValueBytes);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. 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. |
-
net8.0
- Grpc.AspNetCore.Server (>= 2.57.0)
- JAAvila.FluentOperations (>= 1.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.