mirror of
https://github.com/yawaflua/WebSockets.git
synced 2025-12-09 20:09:32 +02:00
Replaces `Dictionary` with `ConcurrentDictionary` for thread-safe WebSocket route management and improves error logging with added debug assertions. Also fixes duplicate registrations, enhances dependency injection, updates package references, and adjusts WebSocket attribute structure for better extensibility and usage.
32 lines
1.1 KiB
C#
32 lines
1.1 KiB
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,
|
|
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<IWebSocketManager, WebSocketManager>();
|
|
isc.AddTransient<IWebSocketManager, WebSocketManager>();
|
|
isc.AddSingleton<WebSocketMiddleware>();
|
|
return isc;
|
|
}
|
|
|
|
public static IApplicationBuilder UseWebSocketWithSwagger(this IApplicationBuilder app)
|
|
{
|
|
app.UseWebSockets();
|
|
app.UseMiddleware<WebSocketMiddleware>();
|
|
|
|
return app;
|
|
}
|
|
} |