Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocketHandler and WebSocketConnectionManager lifetime #73

Open
okubiak opened this issue Aug 1, 2018 · 1 comment
Open

WebSocketHandler and WebSocketConnectionManager lifetime #73

okubiak opened this issue Aug 1, 2018 · 1 comment

Comments

@okubiak
Copy link

okubiak commented Aug 1, 2018

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

@sososu
Copy link

sososu commented Aug 11, 2020

I totally agree with you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants