Skip to content

Commit 33c2965

Browse files
author
Jacques Kang
committed
update readme and namespaces
1 parent 33779b7 commit 33c2965

File tree

10 files changed

+147
-17
lines changed

10 files changed

+147
-17
lines changed

README.md

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,133 @@
11
# IpcServiceFramework
2-
.NET Core Inter-process communication framework
2+
3+
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).
4+
5+
[ASP.NET Core Dependency Injection framework](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection) friendly.
6+
7+
## Usage
8+
1. Create an interface as service contract (ideally package in a shared assembly)
9+
2. On client side, implement a proxy with help of abstract class provided by framework
10+
3. On server side, implement the service and register in IoC container
11+
12+
## Sample:
13+
14+
1. Service contract
15+
```csharp
16+
using System.Threading.Tasks;
17+
18+
namespace IpcServiceSample.Contracts
19+
{
20+
public interface IMyIpcService
21+
{
22+
Task<MyResponse> GetDataAsync(MyRequest request, bool iAmHandsome);
23+
}
24+
25+
public class MyRequest
26+
{
27+
public string Message { get; set; }
28+
}
29+
30+
public class MyResponse
31+
{
32+
public string Message { get; set; }
33+
}
34+
}
35+
```
36+
37+
2. Client side
38+
39+
```csharp
40+
using IpcServiceSample.Contracts;
41+
using JKang.IpcServiceFramework;
42+
using System;
43+
using System.Threading.Tasks;
44+
45+
namespace IpcServiceSample.ConsoleClient
46+
{
47+
// implement proxy
48+
class MyClient : IpcServiceClient<IMyIpcService>, IMyIpcService
49+
{
50+
public MyClient(string pipeName)
51+
: base(pipeName)
52+
{ }
53+
54+
public Task<MyResponse> GetDataAsync(MyRequest request, bool iAmHandsome)
55+
{
56+
return InvokeAsync<MyResponse>(nameof(GetDataAsync), request, iAmHandsome);
57+
}
58+
}
59+
60+
class Program
61+
{
62+
static void Main(string[] args)
63+
{
64+
MainAsync().Wait();
65+
}
66+
67+
private static async Task MainAsync()
68+
{
69+
Console.WriteLine("Invoking IpcService...");
70+
var client = new MyClient("pipeName");
71+
MyResponse response = await client.GetDataAsync(new MyRequest
72+
{
73+
Message = "Hello"
74+
}, iAmHandsome: true);
75+
76+
Console.WriteLine($"Received response: '{response.Message}'");
77+
}
78+
}
79+
}
80+
```
81+
82+
3. Server side
83+
84+
```csharp
85+
using IpcServiceSample.Contracts;
86+
using JKang.IpcServiceFramework;
87+
using Microsoft.Extensions.DependencyInjection;
88+
using System;
89+
90+
namespace IpcServiceSample.ConsoleServer
91+
{
92+
// service implementation
93+
public class MyIpcService : IMyIpcService
94+
{
95+
public Task<MyResponse> GetDataAsync(MyRequest request, bool iAmHandsome)
96+
{
97+
var response = new MyResponse
98+
{
99+
Message = $"What you said '{request.Message}' is {(iAmHandsome ? "correct." : "wrong")}"
100+
};
101+
return Task.FromResult(response);
102+
}
103+
}
104+
105+
class Program
106+
{
107+
static void Main(string[] args)
108+
{
109+
// build service provider
110+
IServiceCollection services = ConfigureServices(new ServiceCollection());
111+
ServiceProvider serviceProvider = services.BuildServiceProvider();
112+
113+
// start IPC service host
114+
IpcServiceHostBuilder
115+
.Buid("pipeName", serviceProvider as IServiceProvider)
116+
.Start();
117+
118+
}
119+
120+
private static IServiceCollection ConfigureServices(IServiceCollection services)
121+
{
122+
return services
123+
.AddScoped<IMyIpcService, MyIpcService>() // IoC registeration
124+
;
125+
}
126+
}
127+
}
128+
```
129+
130+
I'll publish a NuGet package soon.
131+
132+
Any contributions or comments are welcome!
133+

src/IpcServiceSample.ConsoleClient/MyClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using JKang.IpcServiceFramework;
2-
using System;
1+
using IpcServiceSample.ServiceContracts;
2+
using JKang.IpcServiceFramework;
33
using System.Threading.Tasks;
44

55
namespace IpcServiceSample.ConsoleClient

src/IpcServiceSample.ConsoleClient/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using IpcServiceSample.ServiceContracts;
2+
using System;
23
using System.Threading.Tasks;
34

45
namespace IpcServiceSample.ConsoleClient

src/IpcServiceSample.ConsoleServer/MyIpcService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Extensions.Logging;
1+
using IpcServiceSample.ServiceContracts;
2+
using Microsoft.Extensions.Logging;
23
using System.Threading.Tasks;
34

45
namespace IpcServiceSample.ConsoleServer

src/IpcServiceSample.ConsoleServer/Program.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using JKang.IpcServiceFramework;
2-
using Microsoft.Extensions.Configuration;
1+
using IpcServiceSample.ServiceContracts;
2+
using JKang.IpcServiceFramework;
33
using Microsoft.Extensions.DependencyInjection;
44
using Microsoft.Extensions.Logging;
55
using System;
@@ -8,14 +8,8 @@ namespace IpcServiceSample.ConsoleServer
88
{
99
class Program
1010
{
11-
public static IConfigurationRoot Configuration { get; private set; }
12-
1311
static void Main(string[] args)
1412
{
15-
// build configuration
16-
IConfigurationBuilder builder = new ConfigurationBuilder();
17-
Configuration = builder.Build();
18-
1913
// build service provider
2014
IServiceCollection services = ConfigureServices(new ServiceCollection());
2115
ServiceProvider serviceProvider = services.BuildServiceProvider();

src/IpcServiceSample.ServiceContracts/IMyIpcService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Threading.Tasks;
22

3-
namespace IpcServiceSample
3+
namespace IpcServiceSample.ServiceContracts
44
{
55
public interface IMyIpcService
66
{

src/IpcServiceSample.ServiceContracts/IpcServiceSample.ServiceContracts.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<RootNamespace>IpcServiceSample</RootNamespace>
5+
<RootNamespace>IpcServiceSample.ServiceContracts</RootNamespace>
66
</PropertyGroup>
77

88
</Project>

src/IpcServiceSample.ServiceContracts/MyRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace IpcServiceSample
1+
namespace IpcServiceSample.ServiceContracts
22
{
33
public class MyRequest
44
{

src/IpcServiceSample.ServiceContracts/MyResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace IpcServiceSample
1+
namespace IpcServiceSample.ServiceContracts
22
{
33
public class MyResponse
44
{

src/JKang.IpcServiceFramework/JKang.IpcServiceFramework.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6+
<Version>1.0.0</Version>
7+
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
58
</PropertyGroup>
69

710
<ItemGroup>

0 commit comments

Comments
 (0)