Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generic host): implement UseSignalR for generic host #83

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(generic host): implement UseSignalR for generic host
  • Loading branch information
stephenlautier committed Jun 13, 2019
commit 2dbbfdc6be1888eccd84727f2f08d65190d0ec13
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void ConfigureServices(IServiceCollection services)
{
...
services
.AddSingleton<IClusterClient>(client);
.AddSingleton<IClusterClient>(client)
.AddSignalR()
.AddOrleans();
...
Expand Down
3 changes: 3 additions & 0 deletions src/SignalR.Orleans/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace SignalR.Orleans
public static class Constants
{
public const string PUBSUB_PROVIDER = "PubSubStore";
// todo: ideally it doesnt use the default name so consumers can replace the provider and not affecting the default - it will be breaking tho.
//public const string PUBSUB_PROVIDER = "ORLEANS_SIGNALR_PUBSUB_PROVIDER";

public const string STORAGE_PROVIDER = "ORLEANS_SIGNALR_STORAGE_PROVIDER";

public const string SERVERS_STREAM = "SERVERS_STREAM";
Expand Down
7 changes: 6 additions & 1 deletion src/SignalR.Orleans/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
using SignalR.Orleans;
using SignalR.Orleans.Clients;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
public static class OrleansServerExtensions
{
#pragma warning disable 618
[Obsolete("Use UseSignalR(this ISiloBuilder builder, Action<SignalrOrleansSiloConfigBuilder> configure = null) from Orleans.Hosting instead.")]
public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, Action<SignalrServerConfig> config)
{
var cfg = new SignalrServerConfig();
Expand All @@ -18,10 +21,12 @@ public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, Action<
return builder.UseSignalR(cfg);
}

public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, SignalrServerConfig config = null)
[Obsolete("Use UseSignalR(this ISiloBuilder builder, Action<SignalrOrleansSiloConfigBuilder> configure = null) from Orleans.Hosting instead.")]
public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, SignalrServerConfig config)
{
if (config == null)
config = new SignalrServerConfig();
#pragma warning restore 618

config.ConfigureBuilder?.Invoke(builder, new HostBuilderConfig());

Expand Down
73 changes: 73 additions & 0 deletions src/SignalR.Orleans/HostingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using SignalR.Orleans;
using SignalR.Orleans.Clients;

// ReSharper disable once CheckNamespace
namespace Orleans.Hosting
{
public static class SiloBuilderExtensions
{
public static ISiloBuilder UseSignalR(this ISiloBuilder builder, Action<SignalrOrleansSiloConfigBuilder> configure = null)
{
var cfg = new SignalrOrleansSiloConfigBuilder();
configure?.Invoke(cfg);

cfg.ConfigureBuilder?.Invoke(builder, new HostBuilderConfig());

try
{
builder.AddMemoryGrainStorage(Constants.PUBSUB_PROVIDER);
}
catch
{
/** PubSubStore was already added. Do nothing. **/
}

try
{
builder.AddMemoryGrainStorage(Constants.STORAGE_PROVIDER);
}
catch
{
/** Grain storage provider was already added. Do nothing. **/
}

return builder
.AddSimpleMessageStreamProvider(Constants.STREAM_PROVIDER, opt => opt.FireAndForgetDelivery = cfg.UseFireAndForgetDelivery)
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ClientGrain).Assembly).WithReferences());
}
}

public static class SiloHostBuilderExtensions
{
public static ISiloHostBuilder UseSignalR(this ISiloHostBuilder builder, Action<SignalrOrleansSiloHostConfigBuilder> configure = null)
{
var cfg = new SignalrOrleansSiloHostConfigBuilder();
configure?.Invoke(cfg);

cfg.ConfigureBuilder?.Invoke(builder, new HostBuilderConfig());

try
{
builder.AddMemoryGrainStorage(Constants.PUBSUB_PROVIDER);
}
catch
{
/** PubSubStore was already added. Do nothing. **/
}

try
{
builder.AddMemoryGrainStorage(Constants.STORAGE_PROVIDER);
}
catch
{
/** Grain storage provider was already added. Do nothing. **/
}

return builder
.AddSimpleMessageStreamProvider(Constants.STREAM_PROVIDER, opt => opt.FireAndForgetDelivery = cfg.UseFireAndForgetDelivery)
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(ClientGrain).Assembly).WithReferences());
}
}
}
43 changes: 43 additions & 0 deletions src/SignalR.Orleans/SignalrConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,59 @@ namespace SignalR.Orleans
{
public class HostBuilderConfig
{
/// <summary>
/// Gets the storage provider name which is used for registration.
/// </summary>
public string StorageProvider { get; } = Constants.STORAGE_PROVIDER;

/// <summary>
/// Gets the pubsub provider name which is used for registration.
/// </summary>
public string PubSubProvider { get; } = Constants.PUBSUB_PROVIDER;
}

[Obsolete("Use SignalrOrleansSiloHostConfigBuilder instead.")]
public class SignalrServerConfig
{
public Action<ISiloHostBuilder, HostBuilderConfig> ConfigureBuilder { get; set; }
public bool UseFireAndForgetDelivery { get; set; }
}

public class SignalrOrleansConfigBaseBuilder
{
public bool UseFireAndForgetDelivery { get; set; }
}

public class SignalrOrleansSiloConfigBuilder : SignalrOrleansConfigBaseBuilder
{
internal Action<ISiloBuilder, HostBuilderConfig> ConfigureBuilder { get; set; }

/// <summary>
/// Configure builder, such as providers.
/// </summary>
/// <param name="configure">Configure action. This may be called multiple times.</param>
public SignalrOrleansSiloConfigBuilder Configure(Action<ISiloBuilder, HostBuilderConfig> configure)
{
ConfigureBuilder += configure;
return this;
}
}

public class SignalrOrleansSiloHostConfigBuilder : SignalrOrleansConfigBaseBuilder
{
internal Action<ISiloHostBuilder, HostBuilderConfig> ConfigureBuilder { get; set; }

/// <summary>
/// Configure builder, such as providers.
/// </summary>
/// <param name="configure">Configure action. This may be called multiple times.</param>
public SignalrOrleansSiloHostConfigBuilder Configure(Action<ISiloHostBuilder, HostBuilderConfig> configure)
{
ConfigureBuilder += configure;
return this;
}
}

public class SignalrClientConfig
{
public bool UseFireAndForgetDelivery { get; set; }
Expand Down