Aid.Microservice.Client.AspNetCore 2.3.0

dotnet add package Aid.Microservice.Client.AspNetCore --version 2.3.0
                    
NuGet\Install-Package Aid.Microservice.Client.AspNetCore -Version 2.3.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="2.3.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="2.3.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 2.3.0
                    
#r "nuget: Aid.Microservice.Client.AspNetCore, 2.3.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@2.3.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=2.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Aid.Microservice.Client.AspNetCore&version=2.3.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;

var builder = WebApplication.CreateBuilder(args);

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

var app = builder.Build();

2. Use in Endpoints

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

3. Use in Controllers

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

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
2.3.0 98 4/11/2026
2.2.0 107 4/10/2026
2.1.0 120 12/28/2025
2.0.0 114 12/28/2025
1.0.1 289 7/20/2025
1.0.0 123 7/19/2025