LinKit.Grpc 1.0.2

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

LinKit.Grpc

LinKit.Grpc extends LinKit.Core to provide automatic gRPC server and client code generation based on your CQRS requests and handlers. The goal is to remove boilerplate, eliminate manual mapping, and let you focus on business logic.


🚀 Features

gRPC Server

  • Generate gRPC service implementations from CQRS requests marked with [GrpcEndpoint].
  • Automatic request/response → gRPC message mapping.
  • Seamless integration with LinKit mediator.

gRPC Client

  • Generate mediator-friendly gRPC client calls from CQRS requests marked with [GrpcClient].
  • Built-in support for interceptors (logging, retry, authentication, …).
  • Automatic Metadata (headers) injection.

Mapping

  • Automatic property mapping by name.
  • Supports [JsonPropertyName] and LinKit.Core mapping configuration.

Runtime

  • NativeAOT & Trimming Ready.

📦 Installation

dotnet add package LinKit.Grpc

⚡ Quick Start

1. Server

CQRS request:

[GrpcEndpoint(typeof(UserServiceBase), "GetUser")]
public class GetUserQuery : IQuery<UserDto>
{
    public int Id { get; set; }
}

Handler:

[CqrsHandler]
public class GetUserHandler : IQueryHandler<GetUserQuery, UserDto>
{
    public Task<UserDto> HandleAsync(GetUserQuery query, CancellationToken ct)
        => Task.FromResult(new UserDto { Id = query.Id, Name = "Demo" });
}

Register gRPC server:

builder.Services.AddLinKitGrpcServer();
app.MapGrpcService<LinKitUserService>();

2. Client

CQRS request:

[GrpcClient(typeof(UserServiceClient), "GetUserAsync")]
public class GetUserQuery : IQuery<UserDto>
{
    public int Id { get; set; }
}

Register gRPC client:

builder.Services.AddLinKitGrpcClient();

// --- Required ---
// Option 1: simple URL configuration
builder.Services.AddGrpcChannel("https://localhost:5001");

// Option 2: custom provider (multiple URLs, SSL, advanced setup)
builder.Services.AddGrpcChannelProvider<MyChannelProvider>();

// --- Optional ---
// Add interceptors (logging, retry, auth, …)
builder.Services.AddGrpcInterceptorProvider<MyInterceptorProvider>();

// Add metadata (headers) provider
builder.Services.AddGrpcMetadataProvider<MyMetadataProvider>();

Send via mediator:

var user = await mediator.QueryAsync(new GetUserQuery { Id = 1 });

3. Channel Provider Example

public class MyChannelProvider : IGrpcChannelProvider
{
    private readonly Dictionary<Type, string> _serviceUrls = new()
    {
        { typeof(UserService.UserServiceClient), "https://localhost:5001" },
        { typeof(OrderService.OrderServiceClient), "https://orders.myapi.com" }
    };

    public GrpcChannel GetChannel(Type clientType)
    {
        // Select endpoint URL by client type
        if (!_serviceUrls.TryGetValue(clientType, out var url))
        {
            throw new InvalidOperationException(
                $"No gRPC endpoint configured for client type {clientType.FullName}");
        }

        // Configure HttpClientHandler (SSL, certificates, etc.)
        var httpHandler = new HttpClientHandler
        {
            // Example: allow self-signed certs in dev
            ServerCertificateCustomValidationCallback = 
                HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
        };

        // Configure channel options
        var channelOptions = new GrpcChannelOptions
        {
            HttpHandler = httpHandler,
            MaxReceiveMessageSize = 2 * 1024 * 1024, // 2 MB
            MaxSendMessageSize = 2 * 1024 * 1024
        };

        return GrpcChannel.ForAddress(url, channelOptions);
    }
}

4. Interceptor Example

public class MyInterceptorProvider : IGrpcInterceptorProvider
{
    public Interceptor[] GetInterceptors(Type clientType)
        => new Interceptor[] { new LoggingInterceptor() };
}

🔧 Configuration

  • [GrpcEndpoint] → expose a CQRS request as a gRPC method.
  • [GrpcClient] → generate gRPC client code for a CQRS request.
  • Mapping is automatic but can be customized with LinKit.Core mapping configuration.
  • Interceptors + metadata providers let you implement cross-cutting concerns (auth, logging, retry).

✅ Notes

  • Channels are provided by IGrpcChannelProvider.

    • Do not call GrpcChannel.ForAddress directly on every request.
    • The factory ensures channel reuse for performance.
  • Intercept is applied on a CallInvoker, not directly on GrpcChannel. Generated code uses:

    var callInvoker = channel.Intercept(interceptors);
    var client = new UserServiceClient(callInvoker);
    
  • Separation of channel, interceptor, and metadata providers makes it easy to swap or extend.


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 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. 
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.0.3 51 9/26/2025
1.0.2 73 9/26/2025
1.0.1 81 9/26/2025
1.0.0 107 9/5/2025