Files
WebSockets/yawaflua.WebSockets/ServiceBindings.cs
Dmitri Shimanski 4a22cf3337 Adds onOpenHandler
2025-03-29 04:22:57 +03:00

26 lines
857 B
C#

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using yawaflua.WebSockets.Core;
using yawaflua.WebSockets.Core.Middleware;
using yawaflua.WebSockets.Models.Interfaces;
namespace yawaflua.WebSockets;
public static class ServiceBindings
{
public static IServiceCollection SettingUpWebSockets(this IServiceCollection isc, Action<WebSocketOptions>? socketOptions = null)
{
isc.AddSingleton<WebSocketRouter>();
isc.AddScoped<IWebSocketManager, WebSocketManager>();
isc.AddSingleton<WebSocketMiddleware>();
isc.Configure("WebSocketOptions", socketOptions);
return isc;
}
public static IApplicationBuilder ConnectWebSockets(this IApplicationBuilder iab)
{
iab.UseWebSockets();
iab.UseMiddleware<WebSocketMiddleware>();
return iab;
}
}