Skip to content

Commit

Permalink
refactor(extensions): add extensions for simple usage (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
claylaut authored and galvesribeiro committed Feb 12, 2019
1 parent 48c62ed commit 28eda56
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
25 changes: 21 additions & 4 deletions README.Nuget.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,39 @@ We need to configure the Orleans Silo with the below:
***Example***
```cs
var silo = new SiloHostBuilder()
.UseSignalR()
.UseSignalR()
.Build();

await silo.StartAsync();
```

### Configure Silo Storage Provider and Grain Persistance
Optional configuration to override the default implementation for both providers which by default are set as `Memory`.

***Example***
```cs
.UseSignalR(cfg =>
{
cfg.ConfigureBuilder = (builder, config) =>
{
builder
.AddMemoryGrainStorage(config.PubSubProvider)
.AddMemoryGrainStorage(config.StorageProvider);
};
})
```

## Client
Now your SignalR application needs to connect to the Orleans Cluster by using an Orleans Client:
* Use `.UseSignalR()` on `IClientBuilder`.

***Example***
```cs

var client = new ClientBuilder()
.UseSignalR()
.Build();
await client.Connect();

await client.Connect();
```

Somewhere in your `Startup.cs`:
Expand Down Expand Up @@ -61,4 +78,4 @@ public class UserNotificationGrain : Grain<UserNotificationState>, IUserNotifica
await _hubContext.User(this.GetPrimaryKeyString()).SendSignalRMessage("Broadcast", State.UserNotification);
}
}
```
```
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Installation is performed via [NuGet](https://www.nuget.org/packages/SignalR.Orl

From Package Manager:

> PS> Install-Package SignalR.Orleans -prerelease
> PS> Install-Package SignalR.Orleans
.Net CLI:

> \# dotnet add package SignalR.Orleans -prerelease
> \# dotnet add package SignalR.Orleans
Paket:
Paket:

> \# paket add SignalR.Orleans -prerelease
> \# paket add SignalR.Orleans
# Configuration

Expand All @@ -38,16 +38,29 @@ We need to configure the Orleans Silo with the below:

***Example***
```cs
var siloPort = 11111;
int gatewayPort = 30000;
var siloAddress = IPAddress.Loopback;

var silo = new SiloHostBuilder()
.UseSignalR()
.Build();

await silo.StartAsync();
```

### Configure Silo Storage Provider and Grain Persistance
Optional configuration to override the default implementation for both providers which by default are set as `Memory`.

***Example***
```cs
.UseSignalR(cfg =>
{
cfg.ConfigureBuilder = (builder, config) =>
{
builder
.AddMemoryGrainStorage(config.PubSubProvider)
.AddMemoryGrainStorage(config.StorageProvider);
};
})
```

## Client
Now your SignalR application needs to connect to the Orleans Cluster by using an Orleans Client:
* Use `.UseSignalR()` on `IClientBuilder`.
Expand All @@ -57,7 +70,8 @@ Now your SignalR application needs to connect to the Orleans Cluster by using an
var client = new ClientBuilder()
.UseSignalR()
.Build();
await client.Connect();

await client.Connect();
```

Somewhere in your `Startup.cs`:
Expand Down
17 changes: 17 additions & 0 deletions src/SignalR.Orleans/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Orleans;
Expand All @@ -9,6 +10,14 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class OrleansServerExtensions
{
public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, Action<SignalrServerConfig> config)
{
var cfg = new SignalrServerConfig();
config?.Invoke(cfg);

return builder.UseSignalR(cfg);
}

public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, SignalrServerConfig config = null)
{
if (config == null)
Expand All @@ -30,6 +39,14 @@ public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, Signalr

public static class OrleansClientExtensions
{
public static IClientBuilder UseSignalR(this IClientBuilder builder, Action<SignalrClientConfig> config)
{
var cfg = new SignalrClientConfig();
config?.Invoke(cfg);

return builder.UseSignalR(cfg);
}

public static IClientBuilder UseSignalR(this IClientBuilder builder, SignalrClientConfig config = null)
{
if (config == null)
Expand Down

0 comments on commit 28eda56

Please sign in to comment.