Skip to content

Repository files navigation

NRPC (No RPC)

buildNuGet VersionNuGet Download

NRPC is a .NET library that provides RPC-like programming interfaces using message queue services or other distributed communication facilities. It allows you to create distributed applications with clean service interfaces while abstracting away the underlying communication mechanisms.

Overview

NRPC enables you to:

  • Define service contracts using simple .NET interfaces with attributes
  • Implement RPC-style method calls over various transport mechanisms
  • Support for both synchronous and asynchronous communication patterns
  • Generate proxy implementations at runtime
  • High-performance service execution with pre-compiled method handlers

Project Structure

The repository consists of several components:

  • NRPC.Abstractions: Core interfaces, models, and metadata for RPC communication
  • NRPC.Caller: Client-side implementation for sending requests and handling responses (formerly NRPC.Client)
  • NRPC.Proxy: Dynamic proxy generation for RPC interfaces
  • NRPC.Executor: Server-side implementation for handling requests with compiled service handlers

Getting Started

Installation

dotnet add package NRPC

Usage Example

  1. Define your service interface with the ServiceContract attribute:
usingNRPC.Caller;[ServiceContractAtribute]publicinterfaceICalculator{Task<int>Add(intx,inty);Task<string>Concat(stringx,stringy);TaskExecuteVoid(stringcommand);}
  1. Implement the service:
publicclassCalculatorService:ICalculator{publicTask<int>Add(intx,inty)=>Task.FromResult(x+y);publicTask<string>Concat(stringx,stringy)=>Task.FromResult(x+y);publicTaskExecuteVoid(stringcommand){Console.WriteLine($"Executing: {command}");returnTask.CompletedTask;}}
  1. Create and use the RPC caller:
usingNRPC.Caller;usingNRPC.Abstractions;// Create a connection factory (implement IRpcConnectionFactory)varconnectionFactory=newYourRpcConnectionFactory();// Create the caller factoryvarcallerFactory=newRpcCallerFactory<ICalculator>(connectionFactory);// Create and use the callervarcalculator=awaitcallerFactory.CreateCaller();varresult=awaitcalculator.Add(5,3);// Returns 8
  1. Handle requests on the server side:
usingNRPC.Executor;usingNRPC.Abstractions.Metadata;// Create service handlervarserviceHandler=newCompiledServiceHandler<ICalculator>();varservice=newCalculatorService();// Handle incoming requestvarrequest=newRpcRequest{Method="Add",Parameters=newobject[]{5,3}};varresponse=awaitserviceHandler.HandleRequestAsync(service,request);

Features

  • Interface-based: Define clean service contracts using C# interfaces with ServiceContract attributes
  • Dynamic Proxies: Runtime generation of proxy types for seamless method calls
  • Task-based API: All remote operations are asynchronous by design
  • Transport Abstraction: Independent from the underlying communication mechanism through IRpcConnection
  • High Performance: Pre-compiled service handlers for optimal execution speed
  • Error Handling: Built-in RPC exception handling with detailed error information
  • Metadata System: Rich metadata support for service and method information
  • Extensible: Support for custom serialization, transport, and calling adapters

Key Components

Service Contracts

Mark your interfaces with [ServiceContractAttribute] to define RPC service contracts:

[ServiceContractAttribute]publicinterfaceIMyService{Task<string>GetData(intid);}

RPC Connection

Implement IRpcConnection to define how requests and responses are transmitted:

publicinterfaceIRpcConnection{TaskSendAsync(RpcRequestrequest);Task<RpcResponse>ReceiveAsync(CancellationTokencancellationToken=default);}

Compiled Service Handler

Use CompiledServiceHandler<T> for high-performance server-side request handling with pre-compiled method invocation.

Supported Platforms

  • .NET 6.0+
  • .NET Standard 2.0+

Architecture

NRPC follows a clean architecture with clear separation of concerns:

  • Abstractions Layer: Core interfaces and data models (RpcRequest, RpcResponse, RpcError)
  • Metadata System: Service and method metadata for efficient runtime operations
  • Caller Layer: Client-side proxy generation and request/response handling
  • Executor Layer: Server-side request processing with compiled handlers
  • Proxy Layer: Dynamic proxy generation for transparent method calls

Testing

The project includes comprehensive tests covering:

  • RPC connection workflows
  • Client-to-server communication
  • Service handler functionality
  • Proxy generation and method invocation
  • Error handling scenarios

License

This project is licensed under the terms of the license included in the repository.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

No RPC

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages