Get started with the Azure SignalR Service integration
Esta página aún no está disponible en tu idioma.
Azure SignalR Service is a fully managed real-time messaging service that simplifies adding real-time web functionality to applications. The Aspire Azure SignalR Service integration enables you to connect to Azure SignalR instances from your applications.
In this introduction, you’ll see how to install and use the Aspire Azure SignalR Service integrations in a simple configuration. If you already have this knowledge, see Azure SignalR Service Hosting integration for full reference details.
Set up hosting integration
Section titled “Set up hosting integration”To begin, install the Aspire Azure SignalR Service Hosting integration in your Aspire AppHost project. This integration allows you to create and manage Azure SignalR Service resources from your Aspire hosting projects:
aspire add azure-signalrLa CLI de Aspire es interactiva; asegúrate de seleccionar el resultado adecuado cuando se te pida:
Select an integration to add:
> azure-signalr (Aspire.Hosting.Azure.SignalR)> Other results listed as selectable options...#:package Aspire.Hosting.Azure.SignalR@*<PackageReference Include="Aspire.Hosting.Azure.SignalR" Version="*" />Next, in the AppHost project, create an Azure SignalR Service resource and pass it to the consuming projects:
var builder = DistributedApplication.CreateBuilder(args);
var signalR = builder.AddAzureSignalR("signalr");
var api = builder.AddProject<Projects.ApiService>("api") .WithReference(signalR) .WaitFor(signalR);
builder.AddProject<Projects.WebApp>("webapp") .WithReference(api) .WaitFor(api);
// After adding all resources, run the app...
builder.Build().Run();The preceding code adds an Azure SignalR Service resource named signalr to the AppHost project. The api project references the SignalR service and the webapp project references the API.
Set up hub host integration
Section titled “Set up hub host integration”To use Azure SignalR Service from your hub host applications, install the SignalR package in your project:
dotnet add package Microsoft.Azure.SignalR#:package Microsoft.Azure.SignalR@*<PackageReference Include="Microsoft.Azure.SignalR" Version="*" />In the Program.cs file of your hub host project, configure Azure SignalR Service by chaining calls to .AddSignalR().AddNamedAzureSignalR("name"):
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalR() .AddNamedAzureSignalR("signalr");
var app = builder.Build();
app.MapHub<ChatHub>("/chat");
app.Run();For full details on using the hub host integration, see Azure SignalR Service Hub host integration.