コンテンツにスキップ

Get started with the Azure SignalR Service integration

このコンテンツはまだ日本語訳がありません。

Azure SignalR Service icon

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.

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 CLI — Aspire.Hosting.Azure.SignalR パッケージを追加
aspire add azure-signalr

Aspire CLI は対話的です。求められたら適切な結果を選択してください:

Aspire CLI — 出力例
Select an integration to add:
> azure-signalr (Aspire.Hosting.Azure.SignalR)
> Other results listed as selectable options...

Next, in the AppHost project, create an Azure SignalR Service resource and pass it to the consuming projects:

C# — AppHost.cs
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.

To use Azure SignalR Service from your hub host applications, install the SignalR package in your project:

.NET CLI — Add Microsoft.Azure.SignalR package
dotnet add package Microsoft.Azure.SignalR

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.