OrionGuard.Grpc
7.0.0
dotnet add package OrionGuard.Grpc --version 7.0.0
NuGet\Install-Package OrionGuard.Grpc -Version 7.0.0
<PackageReference Include="OrionGuard.Grpc" Version="7.0.0" />
<PackageVersion Include="OrionGuard.Grpc" Version="7.0.0" />
<PackageReference Include="OrionGuard.Grpc" />
paket add OrionGuard.Grpc --version 7.0.0
#r "nuget: OrionGuard.Grpc, 7.0.0"
#:package OrionGuard.Grpc@7.0.0
#addin nuget:?package=OrionGuard.Grpc&version=7.0.0
#tool nuget:?package=OrionGuard.Grpc&version=7.0.0
OrionGuard.Grpc
A grpc-dotnet server interceptor that validates incoming messages with your IValidator<T> registrations and rejects a bad one with StatusCode.InvalidArgument before the service method runs.
dotnet add package OrionGuard.Grpc
using Microsoft.Extensions.DependencyInjection;
using Moongazing.OrionGuard.DependencyInjection;
using Moongazing.OrionGuard.Grpc;
// protoc generates this from your .proto; shown here so the sample stands on its own.
public sealed class CreateUserRequest
{
public string Email { get; set; } = string.Empty;
}
public sealed class CreateUserRequestValidator : AbstractValidator<CreateUserRequest>
{
public CreateUserRequestValidator()
{
RuleFor(x => x.Email, nameof(CreateUserRequest.Email), p => p.NotEmpty().Email());
}
}
public static class GrpcSetup
{
public static void Add(IServiceCollection services)
{
services.AddOrionGuardGrpc();
services.AddValidator<CreateUserRequest, CreateUserRequestValidator>();
services.AddGrpc(options => options.Interceptors.Add<OrionGuardInterceptor>());
}
}
A caller sending an empty email gets an RpcException with status InvalidArgument (code 3), the error messages joined with "; " as the status detail, and one trailer, validation-errors-json, holding a JSON array such as [{"ParameterName":"Email","Message":"Email must be a valid email."}]. The service method is not entered. The core OrionGuard package comes along as a dependency; keep using Grpc.AspNetCore (or Grpc.Tools with Google.Protobuf) for code generation.
Reading the errors on the client
using Grpc.Core;
public static class ClientSide
{
public static string? ErrorsFrom(RpcException ex) =>
ex.StatusCode == StatusCode.InvalidArgument
? ex.Trailers.GetValue("validation-errors-json")
: null;
}
What the interceptor does
- Unary and server-streaming calls: the request is validated before the service method runs.
- Client-streaming and duplex calls: each incoming message is validated as the service reads it (
MoveNext). - Every
IValidator<T>registered for the message's runtime type runs throughValidateAsync, one after another, soRuleForAsyncrules run and the errors are combined. - Validators come from the call's request scope (
HttpContext.RequestServices), so a scoped validator, or one holding a scopedDbContext, works.
AddOrionGuardGrpc() only registers OrionGuardInterceptor as a singleton; you add it to the pipeline in AddGrpc yourself, and register each validator yourself.
What this does not do
- It does not find your validators. No assembly scanning; a message type with no registered validator passes through unvalidated.
- On a client-streaming or duplex call it fails at the first bad message — the messages read before it have already been handed to your code. There is no all-or-nothing over a stream.
- It never validates what the server sends back. Response messages and streamed replies are not checked.
- The errors are a string and a trailer, not
google.rpc.BadRequest. A non-.NET client has to parsevalidation-errors-jsonitself; nothing in the standard richer-error model is emitted. - proto3 has no "absent" for scalars. A missing
stringarrives as""and a missingint32as0, soNotEmpty()cannot distinguish "not sent" from "sent empty". Useoptionalfields or a wrapper type in the.protowhen that difference matters. - Outside an ASP.NET Core host there is no request scope. A service hosted some other way falls back to the provider the interceptor was constructed with, where a scoped validator cannot be resolved.
Targets
net8.0, net9.0, net10.0; grpc-dotnet 2.x (Grpc.AspNetCore.Server).
With the rest of OrionGuard
OrionGuard · OrionGuard.AspNetCore · OrionGuard.OpenTelemetry
Documentation
License
MIT. See LICENSE.txt.
| 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 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 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
- Grpc.AspNetCore.Server (>= 2.83.0)
- OrionGuard (>= 7.0.0)
-
net8.0
- Grpc.AspNetCore.Server (>= 2.83.0)
- OrionGuard (>= 7.0.0)
-
net9.0
- Grpc.AspNetCore.Server (>= 2.83.0)
- OrionGuard (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.0.0 | 86 | 9/20/2026 |
| 6.7.0 | 117 | 7/20/2026 |
| 6.6.2 | 124 | 6/20/2026 |
| 6.6.1 | 116 | 6/20/2026 |
| 6.6.0 | 114 | 6/19/2026 |
| 6.5.30 | 124 | 6/17/2026 |
| 6.5.29 | 116 | 6/15/2026 |
| 6.5.28 | 115 | 6/15/2026 |
| 6.5.27 | 115 | 6/15/2026 |
| 6.5.26 | 112 | 6/13/2026 |
| 6.5.25 | 113 | 6/13/2026 |
| 6.5.24 | 114 | 6/12/2026 |
| 6.5.23 | 119 | 6/12/2026 |
| 6.5.22 | 117 | 6/11/2026 |
| 6.5.21 | 112 | 6/11/2026 |
| 6.5.20 | 111 | 6/11/2026 |
| 6.5.19 | 109 | 6/11/2026 |
| 6.5.18 | 107 | 6/11/2026 |
| 6.5.16 | 116 | 6/11/2026 |
| 6.5.15 | 113 | 6/11/2026 |