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

WebSocketHandler and WebSocketConnectionManager lifetime

Open okubiak opened this issue 6 years ago • 1 comments

Hi,

Any reason to set the WebSocketHandler service as a Singleton and WebSocketConnectionManager service as transient?

From my point of view WebSocketConnectionManager should be a Singleton and WebSocketHandler a transient or scoped service as the entry point for the websocket is the handler, we don't have to keep it as a singleton but allow other scoped DI to be used inside the handler (like for EF #68 - #72)

To be able to keep mapped route to specific handler, I tried to give to the middleware the handler type (like app.MapWebSocketManager<ConnectionHandler>("/connection");) and calling var webSocketHandler = (WebSocketHandler)serviceProvider.GetService(_handlerType); directly in the middleware Invoke function. This is working fine but I don't know if it's the best way to do runtime dependency injection setup.

Regards

okubiak avatar Aug 01 '18 13:08 okubiak

I totally agree with you

sososu avatar Aug 11 '20 06:08 sososu