Adding Azure SignalR Service Dependencies
Understand how to add Azure SignalR Service dependencies to your ASP.NET Core projects, configure SignalR hubs to use Azure, and adapt the IHubContext implementation for seamless cloud integration. This lesson guides you through commands, code changes, and dependency injection needed to offload client messaging to Azure SignalR Service while maintaining server-side logic.
We'll cover the following...
Steps to follow
Step 1: To add Azure SignalR Service dependencies to our application, we need to execute the following command inside SignalRHubs project folder:
cd SignalR-on-.NET-6---the-complete-guide/Chapter-10/Part-02/LearningSignalR/SignalRHubs
dotnet add package Microsoft.Azure.SignalR
Step 2: Next, we can open the Program.cs file of SignalRServer project and replace the line with AddSignalR call with the following:
cd SignalR-on-.NET-6---the-complete-guide/Chapter-10/Part-02/LearningSignalR/SignalRServer/Program.cs
builder.Services.AddSignalR().AddAzureSignalR();
Step 3: We can do the same in SignalRServer2 project. There are two ways of configuring it. The AddAzureSignalR method can accept a string parameter representing the connection string of the Azure SignalR Service we have created earlier. But we can also leave it without the parameter. But to make it work, we will need to use the User Secrets tool inside the project.
If we don’t want to pass the connection string in the code of our Program.cs file, we would need to execute the following command inside the project folder:
dotnet user-secrets init
Step 4: Then, we would need to execute the following command: