Fluent.Unions.Grpc 1.1.0

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

Fluent.Unions

Fluent.Unions.Grpc

NuGet Downloads Publish Documentation

Converts gRPC client calls to Result<T>, so an RpcException becomes an error. On the server, a Grpc.Core interceptor turns the error of a result into an RpcException with a status code. It builds on Fluent.Unions and Grpc.Core.Api (Apache-2.0), so it works with Grpc.Net.Client and Grpc.AspNetCore.

Installation

dotnet add package Fluent.Unions.Grpc

Usage

Client: convert the call.

using Fluent.Unions.Grpc;

Result<UserReply> user = await client.GetUserAsync(new UserRequest { Id = 7 }).ToResult();
// the reply, or an RpcException with the status code only as the error

if (user.TryGetError(out var error) && error is RpcException { StatusCode: StatusCode.NotFound })
    // handle it

Server: a response is a protobuf message, not a Result, so the service method unwraps the result with Check() and the interceptor maps the error.

builder.Services.AddGrpc(grpc => grpc.Interceptors.Add<ResultServerInterceptor>());

public override async Task<UserReply> GetUser(UserRequest request, ServerCallContext context) =>
    (await users.Find(request.Id)).Check().GetValue();

KeyNotFoundException becomes NotFound, a ValidationError or ValidationErrors becomes InvalidArgument with its messages and member names. An RpcException is passed on as it is. Map your own errors with ResultGrpcOptions, configured with the options pattern:

builder.Services.Configure<ResultGrpcOptions>(options => options.Map<OutOfStockException>(StatusCode.FailedPrecondition, exposeMessage: true));

error.ToRpcException() does the same mapping by hand.

With your own result type

ToResult() produces the default Fluent.Unions.Result<T>. To get your own type, wrap the call in your own Result.TryAsync(...), or convert with Match. See your own result type.

Shop.Result<UserReply> mine = user.Match(value => (Shop.Result<UserReply>)value, error => DomainException.FromException(error));

Documentation

Rules

  • Unary and client-streaming calls. ToResult() covers calls with a single response. For a streaming response, the RpcException comes out of ResponseStream.MoveNext.
  • Only RpcException is an error. Other exceptions are thrown. The error keeps the status code but not the detail or trailers of the downstream call, so it can be returned without leaking them. The original is Status.DebugException.
  • Cancellation is not an error. A call with the status Cancelled throws OperationCanceledException, with the RpcException as its InnerException.
  • Messages stay hidden. A mapped exception's message reaches the client only with exposeMessage; validation errors always list theirs. An unmapped exception is rethrown by the interceptor, so gRPC reports it as usual.
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
1.1.0 91 11/22/2026
1.0.0 93 11/21/2026
0.3.0 95 11/20/2026