Skip to content

Commit c3fa0e2

Browse files
authored
Update README.md
1 parent 2ba9667 commit c3fa0e2

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@ public class GameController : WebSocketController
8585
}
8686
}
8787
```
88+
## Providing dependencies in controller
89+
```csharp
90+
[WebSocket("/chat")]
91+
public class ChatController : WebSocketController
92+
{
93+
public static DbContext dbContext;
94+
95+
public ChatController(DbContext dbContext)
96+
{
97+
ChatController.dbContext = dbContext;
98+
}
99+
100+
[WebSocket("join/{roomId}")]
101+
public async Task JoinRoom(WebSocket webSocket, HttpContext context)
102+
{
103+
await dbContext.Add(...);
104+
// Next your logic etc
105+
}
106+
107+
[WebSocket("leave/{roomId}")]
108+
public async Task LeaveRoom(WebSocket webSocket, HttpContext context)
109+
{
110+
// Handle room leaving
111+
}
112+
}
113+
```
114+
88115

89116
## Lifecycle Management
90117
1. **Connection** - Automatically handled by middleware
@@ -118,4 +145,4 @@ public class GameController : WebSocketController
118145
```
119146

120147
## License
121-
MIT License - Free for commercial and personal use.
148+
[Apache license - Free for commercial and personal use.](LICENSE)

0 commit comments

Comments
 (0)