Skip to content

Commit 9e9923a

Browse files
AdmiralSnydergalvesribeiro
authored andcommitted
fix example for injected HubConnectionBuilder (#28)
1 parent 5f928ea commit 9e9923a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,19 @@ This package implements all public features of SignalR Typescript client.
2525

2626
The following snippet shows how to setup the client to send and receive messages using SignalR.
2727

28+
The HubConnectionBuilder needs to get injected, which must be registered:
2829
```c#
29-
var connection = new HubConnectionBuilder()
30+
// in Startup.cs, ConfigureServices()
31+
services.AddTransient<HubConnectionBuilder>();
32+
```
33+
```c#
34+
// in Component class
35+
[Inject]
36+
private HubConnectionBuilder _hubConnectionBuilder { get; set; }
37+
```
38+
```c#
39+
// in Component Initialization code
40+
var connection = _hubConnectionBuilder // the injected one from above.
3041
.WithUrl("/myHub", // The hub URL. If the Hub is hosted on the server where the blazor is hosted, you can just use the relative path.
3142
opt =>
3243
{

0 commit comments

Comments
 (0)