websocket-manager
websocket-manager copied to clipboard
WebSocketManagerExtensions: registration of dependencies
Should be the WebSocketConnectionManager registered as singleton instead of user defined WebSocketHandlers?
Imagine the situation where you want to resolve some resources in your WebSocketHandler which are dependent on the request context = so they differ per request.
I think the better implementation is:
public static IServiceCollection AddWebSocketManager(this IServiceCollection services)
{
services.AddSingleton<WebSocketConnectionManager>();
foreach (var type in Assembly.GetEntryAssembly().ExportedTypes)
{
if (type.GetTypeInfo().BaseType == typeof(WebSocketHandler))
{
services.AddScoped(type);
}
}
return services;
}
Nice one! I updated this in my fork too