Skip to content

Commit b539e2a

Browse files
committed
minor updates.
1 parent 16f7180 commit b539e2a

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

articles/azure-web-pubsub/tutorial-build-chat.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ First let's create an empty ASP.NET Core app.
9090
}
9191

9292
app.UseStaticFiles();
93-
9493
app.UseRouting();
9594

9695
app.UseEndpoints(endpoints =>
@@ -120,27 +119,36 @@ You may remember in the [publish and subscribe message tutorial](./tutorial-pub-
120119
dotnet add package Microsoft.Extensions.Azure
121120
```
122121
123-
2. Add a `SampleChatHub` class to handle hub events. And DI the service middleware and service client inside `ConfigureServices`. Don't forget to replace `<connection_string>` with the one of your services.
122+
2. Add a `SampleChatHub` class to handle hub events. And DI the service middleware and service client inside `ConfigureServices()`. Don't forget to replace `<connection_string>` with the one of your services.
124123
125124
```csharp
126-
private sealed class SampleChatHub : WebPubSubHub
125+
public void ConfigureServices(IServiceCollection services)
127126
{
128-
private readonly WebPubSubServiceClient<SampleChatHub> _serviceClient;
127+
services.AddWebPubSub(o => o.ServiceEndpoint = new ServiceEndpoint("<connection_string>"))
128+
.AddWebPubSubServiceClient<SampleChatHub>();
129+
}
129130

130-
public SampleChatHub(WebPubSubServiceClient<SampleChatHub> serviceClient)
131+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
132+
{
133+
if (env.IsDevelopment())
131134
{
132-
_serviceClient = serviceClient;
135+
app.UseDeveloperExceptionPage();
133136
}
137+
138+
app.UseStaticFiles();
139+
app.UseRouting();
140+
141+
app.UseEndpoints(endpoints =>
142+
{
143+
});
134144
}
135-
136-
public void ConfigureServices(IServiceCollection services)
145+
146+
private sealed class SampleChatHub : WebPubSubHub
137147
{
138-
services.AddWebPubSub(o => o.ServiceEndpoint = new ServiceEndpoint("<connection_string>"))
139-
.AddWebPubSubServiceClient<SampleChatHub>();
140148
}
141149
```
142150
143-
`AddWebPubSubServiceClient<THub>` is used to inject the service client, with which we can generate client connection token and invoke service REST APIs when hub events are triggered.
151+
`AddWebPubSubServiceClient<THub>()` is used to inject the service client `WebPubSubServiceClient<THub>`, with which we can use in negotiation step to generate client connection token and in hub methods to invoke service REST APIs when hub events are triggered.
144152
145153
3. Add a `/negotiate` API to the server inside `app.UseEndpoints` to generate the token.
146154
@@ -491,7 +499,7 @@ Here we're using Web PubSub middleware SDK, there is already an implementation t
491499
});
492500
```
493501
494-
2. Go the `SampleChatHub` we created in previous step and override `OnConnectedAsync()` method we'd like server to invoke service when `connected` event is triggered.
502+
2. Go the `SampleChatHub` we created in previous step. Add a constructor to work with `WebPubSubServiceClient<SampleChatHub>` so we can use to invoke service. And override `OnConnectedAsync()` method to respond when `connected` event is triggered.
495503
```csharp
496504
private sealed class SampleChatHub : WebPubSubHub
497505
{
@@ -509,7 +517,7 @@ Here we're using Web PubSub middleware SDK, there is already an implementation t
509517
}
510518
```
511519
512-
In the above code, we use the service client to broadcast a notification message to all and indicate whom is joined.
520+
In the above code, we use the service client to broadcast a notification message to all of whom is joined.
513521
514522
# [JavaScript](#tab/javascript)
515523

0 commit comments

Comments
 (0)