websocket-manager icon indicating copy to clipboard operation
websocket-manager copied to clipboard

WebSocketManagerExtensions: registration of dependencies

Open skorunka opened this issue 8 years ago • 1 comments

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;
	}

skorunka avatar Jun 29 '17 10:06 skorunka

Nice one! I updated this in my fork too

RobSchoenaker avatar Jun 29 '17 13:06 RobSchoenaker