JKang.IpcServiceFramework.Core 1.0.0

A lightweight .NET Core inter-process communication framework allowing invoking a service via named pipeline in a similar way as WCF.

There is a newer version of this package available.
See the version list below for details.
Install-Package JKang.IpcServiceFramework.Core -Version 1.0.0
dotnet add package JKang.IpcServiceFramework.Core --version 1.0.0
<PackageReference Include="JKang.IpcServiceFramework.Core" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JKang.IpcServiceFramework.Core --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Build Status

IpcServiceFramework

A .NET Core lightweight inter-process communication framework allowing invoking a service via named pipeline (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.

ASP.NET Core Dependency Injection framework friendly.

Usage

  1. Create an interface as service contract and package it in an assembly to be shared between server and client.
  2. Implement the service and host it in an console or web applciation
  3. Invoke the service with framework provided proxy client

Sample:

  • Service contract
    public interface IComputingService
    {
        float AddFloat(float x, float y);
    }
  • Service implementation
    class ComputingService : IComputingService
    {
        public float AddFloat(float x, float y)
        {
            return x + y;
        }
    }
  • Invoke the service from client process
    var proxy = new IpcServiceClient<IComputingService>("pipeName");
    float result = await proxy.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
  • Host the service (Console application)
   class Program
    {
        static void Main(string[] args)
        {
            // configure DI
            IServiceCollection services = ConfigureServices(new ServiceCollection());

            // run IPC service host
            IpcServiceHostBuilder
                .Buid("pipeName", services.BuildServiceProvider())
                .Run();
        }

        private static IServiceCollection ConfigureServices(IServiceCollection services)
        {
            return services
                .AddIpc(options =>
                {
                    options.ThreadCount = 4;
                })
                .AddService<IComputingService, ComputingService>();
        }
    }
  • Host the service (Web application)
    public class Program
    {
        public static void Main(string[] args)
        {
            IWebHost webHost = BuildWebHost(args);

            // run the IPC service host in a separated thread because it's blocking
            ThreadPool.QueueUserWorkItem(StartIpcService,
                webHost.Services.CreateScope().ServiceProvider);

            webHost.Run();
        }

        private static void StartIpcService(object state)
        {
            var serviceProvider = state as IServiceProvider;
            IpcServiceHostBuilder
                .Buid("pipeName", serviceProvider as IServiceProvider)
                .Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddIpc(options =>
                {
                    options.ThreadCount = 4;
                })
                .AddService<IComputingService, ComputingService>()
                ;
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }

I'll publish NuGet packages later.

Any contributions or comments are welcome!

Build Status

IpcServiceFramework

A .NET Core lightweight inter-process communication framework allowing invoking a service via named pipeline (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.

ASP.NET Core Dependency Injection framework friendly.

Usage

  1. Create an interface as service contract and package it in an assembly to be shared between server and client.
  2. Implement the service and host it in an console or web applciation
  3. Invoke the service with framework provided proxy client

Sample:

  • Service contract
    public interface IComputingService
    {
        float AddFloat(float x, float y);
    }
  • Service implementation
    class ComputingService : IComputingService
    {
        public float AddFloat(float x, float y)
        {
            return x + y;
        }
    }
  • Invoke the service from client process
    var proxy = new IpcServiceClient<IComputingService>("pipeName");
    float result = await proxy.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
  • Host the service (Console application)
   class Program
    {
        static void Main(string[] args)
        {
            // configure DI
            IServiceCollection services = ConfigureServices(new ServiceCollection());

            // run IPC service host
            IpcServiceHostBuilder
                .Buid("pipeName", services.BuildServiceProvider())
                .Run();
        }

        private static IServiceCollection ConfigureServices(IServiceCollection services)
        {
            return services
                .AddIpc(options =>
                {
                    options.ThreadCount = 4;
                })
                .AddService<IComputingService, ComputingService>();
        }
    }
  • Host the service (Web application)
    public class Program
    {
        public static void Main(string[] args)
        {
            IWebHost webHost = BuildWebHost(args);

            // run the IPC service host in a separated thread because it's blocking
            ThreadPool.QueueUserWorkItem(StartIpcService,
                webHost.Services.CreateScope().ServiceProvider);

            webHost.Run();
        }

        private static void StartIpcService(object state)
        {
            var serviceProvider = state as IServiceProvider;
            IpcServiceHostBuilder
                .Buid("pipeName", serviceProvider as IServiceProvider)
                .Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddIpc(options =>
                {
                    options.ThreadCount = 4;
                })
                .AddService<IComputingService, ComputingService>()
                ;
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
    }

I'll publish NuGet packages later.

Any contributions or comments are welcome!

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.2 1,802 4/30/2019
2.2.1 364 3/28/2019
2.2.0 1,398 12/18/2018
2.1.2 685 12/11/2018
2.1.1 207 11/20/2018
2.1.0 134 11/19/2018
2.0.3 163 11/16/2018
2.0.2 155 11/14/2018
2.0.1.1 706 10/29/2018
2.0.0.2 522 7/16/2018
1.0.4.3 219 7/13/2018
1.0.3 231 6/30/2018
1.0.2 234 5/30/2018
1.0.1 1,837 2/14/2018
1.0.0 364 1/9/2018
Show less