Aid.Microservice.Client.AspNetCore 3.0.0

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

Aid.Microservice.Client.AspNetCore

ASP.NET Core integration for the Aid.Microservice RPC client. Provides DI-based registration and a shared connection pool for your web application.

Quick Start

1. Register the Client

using Aid.Microservice.Client.AspNetCore;
using Aid.Microservice.Generated;

var builder = WebApplication.CreateBuilder(args);

// Loads "RabbitMqConfiguration" from appsettings.json
builder.Services.AddAidMicroserviceClient();

// Registers source-generated typed client proxies (optional)
builder.Services.AddAidMicroserviceGeneratedClients();

var app = builder.Build();

2. Use in Endpoints

// Via IRpcClientFactory
app.MapGet("/", async (IRpcClientFactory factory) =>
{
    var client = factory.CreateClient("simple");
    return await client.CallAsync<int>("multiple", new { a = 5, b = 10 });
});

// Or via injected strongly-typed client:
app.MapGet("/calc", async (ICalculatorClient client) => await client.Add(5, 10));

3. Use in Controllers

[ApiController]
[Route("api/[controller]")]
public class RpcController(ISimpleClient client) : ControllerBase
{
    [HttpGet("multiply")]
    public async Task<IActionResult> Multiply(int a, int b)
    {
        var result = await client.Multiple(a, b);
        return Ok(result);
    }
}

Strongly-Typed Clients (Source Generated)

Declare an interface marked with [MicroserviceClient]:

[MicroserviceClient("simple")]
public interface ISimpleClient
{
    [RpcCallable("multiple")]
    Task<int> Multiple(int a, int b, CancellationToken ct = default);
}

Register both the base client infrastructure and generated proxies:

builder.Services.AddAidMicroserviceClient();
builder.Services.AddAidMicroserviceGeneratedClients();

The Source Generator automatically emits a compile-time implementation and registers ISimpleClient in DI, allowing you to inject it anywhere without reflection.

Configuration

{
    "RabbitMqConfiguration": {
        "Hostname": "localhost",
        "Port": 5672,
        "Username": "guest",
        "Password": "guest",
        "RetryCount": 3,
        "RecoveryInterval": 5
    }
}
builder.Services.AddAidMicroserviceClient();

From a Configuration Object

var config = new RabbitMqConfiguration
{
    Hostname = "rabbitmq",
    Port = 5672,
    Username = "user",
    Password = "secret"
};

builder.Services.AddAidMicroserviceClient(config);

From a Configuration Action

builder.Services.AddAidMicroserviceClient(options =>
{
    options.Hostname = builder.Configuration["RABBIT_HOST"] ?? "localhost";
    options.Port = 5672;
    options.Username = "guest";
    options.Password = "guest";
});

Using Different Protocols

Default Protocol

// Uses DefaultJsonProtocol on "aid_rpc" exchange
var client = factory.CreateClient("simple");
var result = await client.CallAsync<int>("multiple", new { a = 5, b = 10 });

Nameko Protocol (Python Interop)

using Aid.Microservice.Shared.Protocols;

var namekoClient = factory.CreateClient("python_service", new NamekoProtocol());
var result = await namekoClient.CallAsync<int>("add", new { a = 1, b = 2 });

Mixed Service — Different Protocols per Call

app.MapGet("/mixed", async (IRpcClientFactory factory) =>
{
    // Call nameko_add on "nameko-rpc" exchange
    var namekoClient = factory.CreateClient("mixed_service", new NamekoProtocol());
    var namekoResult = await namekoClient.CallAsync<int>("nameko_add", new { a = 10, b = 20 });

    // Call default_add on "aid_rpc" exchange
    var defaultClient = factory.CreateClient("mixed_service");
    var defaultResult = await defaultClient.CallAsync<int>("default_add", new { a = 100, b = 200 });

    return new { nameko = namekoResult, @default = defaultResult };
});

Clients are cached by (serviceName, protocol, exchangeName) — repeated calls with the same parameters reuse the same instance.

Error Handling

app.MapGet("/call", async (IRpcClientFactory factory) =>
{
    try
    {
        var client = factory.CreateClient("simple");
        var result = await client.CallAsync<int>("method", new { a = 1 });
        return Results.Ok(result);
    }
    catch (RpcCallException ex)
    {
        // Server-side error — contains error message, type, and CorrelationId
        return Results.BadRequest(new { error = ex.Message });
    }
    catch (TimeoutException)
    {
        // Call timed out (default: 30s)
        return Results.StatusCode(504);
    }
});

Architecture

AddAidMicroserviceClient()
    │
    ├── Registers IRpcClientFactory as Singleton
    │   ├── Holds one RabbitMQ connection for the entire app
    │   └── Creates lightweight RpcClient per (service, protocol, exchange)
    │
    ├── Registers IRpcProtocol → DefaultJsonProtocol
    │
    └── Registers IRabbitMqConnectionService
        ├── Reads RabbitMqConfiguration from appsettings.json
        └── Manages connection lifecycle (connect, reconnect, dispose)

Passing Arguments

Named Arguments (kwargs) — Default

await client.CallAsync("add", new { a = 1, b = 2 });

Positional Arguments (args) — Nameko

await client.CallAsync("sum", new RpcNamekoRequest(10, 20));

await client.CallAsync("generate",
    new RpcNamekoRequest(
        args: new object[] { "pdf" },
        kwargs: new { async = true }
    )
);

Connection Lifecycle

The connection is managed automatically:

  • Created on first CreateClient() call or first CallAsync()
  • Reused across all clients in the application
  • Disposed when the application shuts down

No manual connection handling is required.

Product Compatible and additional computed target framework versions.
.NET 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
3.0.1 83 8/22/2026
3.0.0 93 8/22/2026
2.4.0 131 7/7/2026
2.3.0 111 4/11/2026
2.2.0 118 4/10/2026
2.1.0 136 12/28/2025
2.0.0 126 12/28/2025
1.0.1 305 7/20/2025
1.0.0 140 7/19/2025