azure-signalr icon indicating copy to clipboard operation
azure-signalr copied to clipboard

Allow configuration Azure:SignalR:Enabled false to disable Azure SignalR

Open vicancy opened this issue 4 years ago • 8 comments

Describe the bug

For netcore31, instead of manually call AddAzureSignalR, you can enable or disable Azure SignalR through config:

{
  "Azure": {
    "SignalR": {
      "Enabled": false
    }
  }
}

However, once AddAzureSignalR is added to code, this configuration never works again, it does not sound a consistent behavior from the user's perspective.

vicancy avatar Dec 18 '20 02:12 vicancy

I was suprised when this didn't work, can this be fixed please? 😃

crackalak avatar Mar 05 '21 16:03 crackalak

If multiple places(configure of Azure:SignalR:Enabled and AddAzureSignalR) are working, it's leads to a problem of which one has higher priority. Customer may be confused that code of AddAzureSignalR() is called but not work as expected.

JialinXin avatar Mar 10 '21 02:03 JialinXin

@davidfowl, any thoughts?

vicancy avatar Mar 10 '21 07:03 vicancy

Are there any updates on this issue? We would love to be able to disable SignalR through Azure:SignalR:Enabled. Should we just remove the call to AddAzureSignalR()?

hasandogu avatar Apr 14 '21 18:04 hasandogu

@hasandogu Yes, remove the call to AddAzureSignalR() will work.

If you're working on netcoreapp3.0+, you're able to switch between local SignalR and Azure SignalR by the simple configuration Azure:SignalR:Enabled. This is the usage for this configuration. See steps below.

Code in startup.cs

  1. ConfigureService like:
public void ConfigureServices(IServiceCollection services)
{
      services.AddSignalR();
}
  1. Configure like
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.UseEndpoints(routes =>
    {
        routes.MapHub<Chat>("/chat");
    }
}
  1. Add Azure SignalR assembly startup in launchSettings.json
"environmentVariables": {
    ...,
    "ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.Azure.SignalR"
  }
  1. Then use Azure:SignalR:Enabled to switch between SignalR/Azure SignalR.

JialinXin avatar Apr 15 '21 02:04 JialinXin

I think it would fundamentally make sense to have an Azure:SignalR:Enabled configuration item that would work even if you have AddAzureSignalR(). The documentation pretty clearly indicates for local dev we should bypass this, but offers no way to do this, absent writing our own conditional configuration code. I tried omiting the connection string, and it throws an exception. Then I found this article and tried the HostingStartupAssemblies setup, but in .net 5 this apparently either does not work or there's more to it then this.

Even if it did work, I think the hostingstartupassemblies way of configuring this is incredibly obtuse and would make it very difficult for developers supporting the app to understand what is happening.

sodablue avatar Sep 14 '21 16:09 sodablue

Another issue is enabling or disabling it based on Configuration provided by custom configuration sources. This Enabled key seems to only be searched for in the HostingEnvironment. It does not take into account custom configuration JSON, or other services that might deliver IConfiguration at runtime.

I would recommend the "on/off" functionality not be at the level of registration, but taken into account by Azure SignalR registered services itself, post startup.

I'm about to write a completely custom version of AddAzureSignalR for this, that injects different implementations for services based on configuration.

My use case is a software product that has both an on-premise version and a cloud version. For teh cloud version, we're going to use Azure SignalR. For the on-premise version, it's up to the user whether to use it or not. And the user's method of configuration may be from a configuration service, or a database. But at a minimum, custom JSON files that are not appsettings.json.

wasabii avatar Jun 04 '22 15:06 wasabii

Any update on this seemingly very simple issue? Why have this setting if it doesn't really do anything? In my case I am attempting to disable/enable per environment and it is proving to be incredibly frustrating as basic configuration does not even seem to work with this product. 😖

Mike-E-angelo avatar Aug 02 '22 09:08 Mike-E-angelo