Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacques Kang committed Jan 9, 2018
1 parent 64fa185 commit a88b70f
Showing 1 changed file with 17 additions and 67 deletions.
84 changes: 17 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ Support multi-threading on server side with configurable number of threads.
2. Implement the service and host it in an console or web applciation
3. Invoke the service with framework provided proxy client

## Sample:
## Downloads

- Service contract
IpcServiceFramework is available via NuGet:

- [JKang.IpcServiceFramework.Core](https://www.nuget.org/packages/JKang.IpcServiceFramework.Core/)
- [JKang.IpcServiceFramework.Server](https://www.nuget.org/packages/JKang.IpcServiceFramework.Server/)
- [JKang.IpcServiceFramework.Client](https://www.nuget.org/packages/JKang.IpcServiceFramework.Client/)

## Quick Start:

### Step 1 - Create service contract
```csharp
public interface IComputingService
{
float AddFloat(float x, float y);
}
```

- Service implementation
### Step 2: Implement the service

```csharp
class ComputingService : IComputingService
Expand All @@ -37,14 +45,7 @@ Support multi-threading on server side with configurable number of threads.
}
```

- Invoke the service from client process

```csharp
var proxy = new IpcServiceClient<IComputingService>("pipeName");
float result = await proxy.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
```

- Host the service (Console application)
### Step 3 - Host the service in Console application

```csharp
class Program
Expand All @@ -71,64 +72,13 @@ Support multi-threading on server side with configurable number of threads.
}
}
```
It's possible to host IPC service in web application, please check out the sample project *IpcServiceSample.WebServer*

- Host the service (Web application)

```csharp
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();
}
```

### Step 4 - Invoke the service from client process

```csharp
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!");
});
}
}
var proxy = new IpcServiceClient<IComputingService>("pipeName");
float result = await proxy.InvokeAsync(x => x.AddFloat(1.23f, 4.56f));
```

I'll publish NuGet packages later.

Any contributions or comments are welcome!

__Please feel free to download, fork and/or provide any feedback!__

0 comments on commit a88b70f

Please sign in to comment.