OrionGuard.Grpc 7.0.0

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

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 through ValidateAsync, one after another, so RuleForAsync rules run and the errors are combined.
  • Validators come from the call's request scope (HttpContext.RequestServices), so a scoped validator, or one holding a scoped DbContext, 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 parse validation-errors-json itself; nothing in the standard richer-error model is emitted.
  • proto3 has no "absent" for scalars. A missing string arrives as "" and a missing int32 as 0, so NotEmpty() cannot distinguish "not sent" from "sent empty". Use optional fields or a wrapper type in the .proto when 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed