File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
901171 . ** 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 )
You can’t perform that action at this time.
0 commit comments