A .NET Core lightweight inter-process communication framework allowing invoking a service via named pipeline and/or TCP (in a similar way as WCF, which is currently unavailable for .NET Core).
Support using primitive or complexe types in service contract.
Support multi-threading on server side with configurable number of threads (named pipeline endpoint only).
ASP.NET Core Dependency Injection framework friendly.
- Create an interface as service contract and package it in an assembly to be shared between server and client.
- Implement the service and host it in an console or web applciation
- Invoke the service with framework provided proxy client
IpcServiceFramework is available via NuGet:
public interface IComputingService
{
float AddFloat(float x, float y);
}
class ComputingService : IComputingService
{
public float AddFloat(float x, float y)
{
return x + y;
}
}
class Program
{
static void Main(string[] args)
{
// configure DI
IServiceCollection services = ConfigureServices(new ServiceCollection());
// build and run service host
new IpcServiceHostBuilder(services.BuildServiceProvider())
.AddNamedPipeEndpoint<IComputingService>(name: "endpoint1", pipeName: "pipeName")
.AddTcpEndpoint<IComputingService>(name: "endpoint2", ipEndpoint: IPAddress.Loopback, port: 45684)
.Build()
.Run();
}
private static IServiceCollection ConfigureServices(IServiceCollection services)
{
return services
.AddIpc()
.AddNamedPipe(options =>
{
options.ThreadCount = 2;
})
.AddService<IComputingService, ComputingService>();
}
}
It's possible to host IPC service in web application, please check out the sample project IpcServiceSample.WebServer
IpcServiceClient<IComputingService> client = new IpcServiceClientBuilder<IComputingService>()
.UseNamedPipe("pipeName") // or .UseTcp(IPAddress.Loopback, 45684) to invoke using TCP
.Build();
float result = await client.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
Please feel free to download, fork and/or provide any feedback!