Adds example of using preConnectionHandler, create OnConnectionHandler(preConnectionHandler), use WebSocketOptions for provides data

This commit is contained in:
Dmitri Shimanski
2025-03-30 00:43:20 +03:00
parent 8661e3eb58
commit b979b9bc22
6 changed files with 40 additions and 9 deletions

View File

@@ -8,12 +8,14 @@ namespace yawaflua.WebSockets;
public static class ServiceBindings
{
public static IServiceCollection SettingUpWebSockets(this IServiceCollection isc, Action<WebSocketOptions>? socketOptions = null)
public static IServiceCollection SettingUpWebSockets(this IServiceCollection isc, WebSocketConfig? socketOptions = null)
{
isc.AddSingleton<WebSocketRouter>();
if (socketOptions != null) isc.AddSingleton(socketOptions);
if (isc.All(k => k.ServiceType != typeof(WebSocketConfig)))
isc.AddSingleton(new WebSocketConfig());
isc.AddScoped<IWebSocketManager, WebSocketManager>();
isc.AddSingleton<WebSocketMiddleware>();
isc.Configure("WebSocketOptions", socketOptions);
return isc;
}