azure-signalr
azure-signalr copied to clipboard
Allow configuration Azure:SignalR:Enabled false to disable Azure SignalR
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.
I was suprised when this didn't work, can this be fixed please? 😃
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.
@davidfowl, any thoughts?
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 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
- ConfigureService like:
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
}
- Configure like
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseEndpoints(routes =>
{
routes.MapHub<Chat>("/chat");
}
}
- Add Azure SignalR assembly startup in launchSettings.json
"environmentVariables": {
...,
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.Azure.SignalR"
}
- Then use
Azure:SignalR:Enabled
to switch between SignalR/Azure SignalR.
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.
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.
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. 😖