AnyProtocol.Generator.CodeFixes
1.0.0
dotnet add package AnyProtocol.Generator.CodeFixes --version 1.0.0
NuGet\Install-Package AnyProtocol.Generator.CodeFixes -Version 1.0.0
<PackageReference Include="AnyProtocol.Generator.CodeFixes" Version="1.0.0" />
<PackageVersion Include="AnyProtocol.Generator.CodeFixes" Version="1.0.0" />
<PackageReference Include="AnyProtocol.Generator.CodeFixes" />
paket add AnyProtocol.Generator.CodeFixes --version 1.0.0
#r "nuget: AnyProtocol.Generator.CodeFixes, 1.0.0"
#:package AnyProtocol.Generator.CodeFixes@1.0.0
#addin nuget:?package=AnyProtocol.Generator.CodeFixes&version=1.0.0
#tool nuget:?package=AnyProtocol.Generator.CodeFixes&version=1.0.0
<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="docs/assets/AnyProtocol_logo_dark.svg"> <source media="(prefers-color-scheme: light)" srcset="docs/assets/AnyProtocol_logo_light.svg"> <img alt="AnyProtocol" src="docs/assets/AnyProtocol_logo_dark.svg" width="420"> </picture> </p>
AnyProtocol
AnyProtocol is a .NET contract-first messaging library. A single interface can be registered as a local service or carried over REST, gRPC, Kafka, RabbitMQ, or ZeroMQ, with request/reply, events, generated proxies, transport validation, health checks, and built-in diagnostics.
One logical server registration can be exposed through several protocols at the same time. Each client selects one protocol in its own configuration; neither the contract nor the service implementation contains transport-specific code.
Stability: The repository targets .NET 10 and the public API is still evolving. Pin package versions, validate transport semantics for your workload, and use the source generator plus serializer metadata before Native AOT deployment. Transport support is intentionally capability-based; a feature listed for one transport is not implied for the others.
Transport matrix
| Transport | Request/reply | Events/pub-sub | Streaming | Delivery | Durability | Ordering |
|---|---|---|---|---|---|---|
| InMemory | Emulated | Yes | Emulated | At most once | Volatile | Per channel |
| REST | Native | No | No | At most once | Volatile | None |
| gRPC | Native | No | Native server streaming | At most once | Volatile | None |
| Kafka | Emulated | Yes | Emulated | At least once | Durable | Per partition |
| RabbitMQ | Emulated | Yes | Emulated | At least once | Durable | Per channel¹ |
| ZeroMQ | Emulated | Yes | Emulated | At most once | Volatile | Per channel |
¹ Per-channel ordering requires one active consumer/handler for the queue; concurrent handlers can complete out of order.
See transport semantics before choosing a production transport.
Prerequisites
- .NET SDK
10.0.300or a compatible newer feature band - A Kafka broker for Kafka transport
- A RabbitMQ broker for RabbitMQ transport
- Reachable TCP endpoints for ZeroMQ
- ASP.NET Core hosting for REST or gRPC servers
From source:
git clone https://github.com/MCKanpolat/AnyProtocol.git
cd AnyProtocol
dotnet restore AnyProtocol.slnx
For an application using Microsoft DI and the local transport:
dotnet add package AnyProtocol.DependencyInjection.Microsoft
dotnet add package AnyProtocol.Protocol.InMemory
dotnet add package AnyProtocol.Serializer.TextJson
Package map
| Purpose | Package |
|---|---|
| Contracts and core pipeline | AnyProtocol, AnyProtocol.Abstraction |
| Microsoft DI and hosted lifecycle | AnyProtocol.DependencyInjection.Microsoft |
| JSON / MessagePack | AnyProtocol.Serializer.TextJson, AnyProtocol.Serializer.MessagePack |
| In-process transport | AnyProtocol.Protocol.InMemory |
| REST client / ASP.NET Core server | AnyProtocol.Protocol.Rest, AnyProtocol.Protocol.Rest.AspNetCore |
| gRPC client / ASP.NET Core server | AnyProtocol.Protocol.Grpc, AnyProtocol.Protocol.Grpc.AspNetCore |
| Kafka / RabbitMQ / ZeroMQ | AnyProtocol.Protocol.Kafka, AnyProtocol.Protocol.RabbitMq, AnyProtocol.Protocol.ZeroMq |
| Optional MCP exposure | AnyProtocol.Mcp, AnyProtocol.Mcp.AspNetCore |
| Compile-time contract generation | AnyProtocol.Generator |
Minimal request/reply
using AnyProtocol.Abstraction;
using AnyProtocol.DependencyInjection.Microsoft;
using AnyProtocol.Protocol.InMemory;
using AnyProtocol.Serializer.TextJson;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddAnyProtocol(link => link
.UseSerializer(new TextJsonMessageSerializer())
.AddTransport("default", new InMemoryMessagingProtocol())
.AddClient<IOrders>()
.AddServer<IOrders, Orders>());
using var host = builder.Build();
await host.StartAsync();
var client = host.Services.GetRequiredService<IOrders>();
var result = await client.GetAsync(new GetOrder("42"), CancellationToken.None);
Console.WriteLine(result.Status);
await host.StopAsync();
[Channel("orders")]
public interface IOrders
{
[Idempotent]
ValueTask<Order> GetAsync(GetOrder request, CancellationToken cancellationToken);
}
public sealed record GetOrder(string Id);
public sealed record Order(string Id, string Status);
public sealed class Orders : IOrders
{
public ValueTask<Order> GetAsync(GetOrder request, CancellationToken cancellationToken)
=> ValueTask.FromResult(new Order(request.Id, "ready"));
}
One service, multiple protocols
Use the built-in ProtocolKey values for compile-time-friendly configuration. Custom keys remain available for third-party protocols or named instances used by different registrations.
link.AddRestServer(ProtocolKey.Rest)
.AddGrpcServer(ProtocolKey.Grpc)
.AddServer<IOrders, Orders>(server => server.UseProtocols(
ProtocolKey.Rest,
ProtocolKey.Grpc,
ProtocolKey.Mcp));
The host maps each selected endpoint once:
services.AddAnyProtocolRest();
services.AddAnyProtocolGrpc();
services.AddAnyProtocolMcp();
app.MapAnyProtocol();
app.MapAnyProtocolGrpc();
app.MapAnyProtocolMcp();
A gRPC client and a REST client keep the same IOrders contract but choose independently:
link.AddClient<IOrders>(client => client.UseProtocol(ProtocolKey.Grpc));
// In another application:
link.AddClient<IOrders>(client => client.UseProtocol(ProtocolKey.Rest));
The choice can come from deployment configuration without changing the contract registration:
services.AddAnyProtocol(
configuration.GetSection("AnyProtocol"),
link => link.AddClient<IOrders>("OrdersClient"));
{
"AnyProtocol": {
"Clients": {
"OrdersClient": { "Protocol": "Grpc" }
}
}
}
Every selected protocol is validated against every contract operation during startup. An incompatible selection fails configuration instead of exposing a partial service. Duplicate native REST/gRPC bindings for one contract are rejected. MCP publishes only methods marked with [McpTool]; selecting MCP without registering and hosting its adapter stops application startup.
[Idempotent] permits configured retries; it does not provide deduplication.
Documentation and samples
- Getting started and transport switching
- Configuration reference
- RabbitMQ guide
- Transport semantics
- Performance methodology
- Deployment
- Observability
- Security
- API reference
- OrderSystem multi-protocol reference
- OrderSystem MCP/REST host
- Native AOT smoke sample
Run the samples with:
dotnet run --project samples/OrderSystem.McpHost
dotnet run --project samples/OrderSystem.McpHost -- --stdio
dotnet run --project samples/AnyProtocol.AotSample
dotnet run --project samples/OrderSystem.MultiProtocol/OrderSystem.Server
dotnet run --project samples/OrderSystem.MultiProtocol/OrderSystem.Client -- --protocol Rest
dotnet run --project samples/OrderSystem.MultiProtocol/OrderSystem.Client -- --protocol Grpc
The multi-protocol order server uses http://localhost:5080 for REST/MCP and http://localhost:5081 for gRPC.
License
AnyProtocol is licensed under LGPL-3.0-or-later. Applications may link to the AnyProtocol libraries under their own license terms. Distributed changes to the AnyProtocol libraries themselves must remain available under LGPL-3.0-or-later with their corresponding source code.
The AnyProtocol name and logo are governed separately by the trademark policy. Forks must not present themselves as the official AnyProtocol project.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
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 |
|---|
See the GitHub release notes for the changes included in this version.