Aid.Microservice.Client.AspNetCore
2.2.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Aid.Microservice.Client.AspNetCore --version 2.2.0
NuGet\Install-Package Aid.Microservice.Client.AspNetCore -Version 2.2.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.2.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.2.0" />
<PackageReference Include="Aid.Microservice.Client.AspNetCore" />
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.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Aid.Microservice.Client.AspNetCore, 2.2.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.2.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.2.0
#tool nuget:?package=Aid.Microservice.Client.AspNetCore&version=2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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
From appsettings.json (recommended)
{
"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 firstCallAsync() - Reused across all clients in the application
- Disposed when the application shuts down
No manual connection handling is required.
| Product | Versions 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.
-
net10.0
- Aid.Microservice.Client (>= 2.2.0)
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection (>= 10.0.1)
- Microsoft.Extensions.Options (>= 10.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.1)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.