4
votes

Hello i have an app up and running using orleans and signalR and i use a HubConnectionBuilder to initialize my SignalRClient like this

public async Task<HubConnection> InitSignalRCLient()
    {
        Program.WriteConsole("Starting SignalR Client...");
        var connection = new HubConnectionBuilder()
            .ConfigureLogging(logging =>
                logging
                .AddProvider(new LogProvider(Log.logger, new LogProviderConfiguration
                {
                    Category = LogCategory.SignalR,
                    Level = LogLevel.Warning
                }))
            )
            .WithUrl(Configuration.GetConnectionString("SignalRInterface"))
            .Build();

And then i add the service as a singleton in the configure service

services.AddSingleton(SignalRClient)

The problem is now that i want to use redis as a backplane to this and i am having issues adding the redis service to my current way of using SignalR like this doesn't work

services.AddSingleton(SignalRClient).AddStackExchangeRedis();

according to the documentation https://docs.microsoft.com/en-us/aspnet/core/signalr/redis-backplane?view=aspnetcore-2.2 it wants you to add it like

services.AddSignalR().AddStackExchangeRedis("<your_Redis_connection_string>");

but that doesn't work with how i use SignalR. Is there anyway to get my implementation to work or anyone got any advice on how to tackle this?

1

1 Answers

5
votes

Try to add in ConfigureServices this:

services.AddDistributedRedisCache(option =>
  {
      option.Configuration = Configuration.GetConnectionString(<your_Redis_connection_string>);
  });

services.AddSignalR().AddStackExchangeRedis(Configuration.GetConnectionString(<your_Redis_connection_string>));

Also add this in Configure

app.UseSignalR(routes =>
  {
     routes.MapHub<your_Hub>("/yourHub");
  });

And don't forget add abortConnect=False in connectionStrings