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

WebSocketManagerExtensions: registration of dependencies #39

Open
skorunka opened this issue Jun 29, 2017 · 1 comment
Open

WebSocketManagerExtensions: registration of dependencies #39

skorunka opened this issue Jun 29, 2017 · 1 comment

Comments

@skorunka
Copy link
Collaborator

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;
	}
@RobSchoenaker
Copy link
Collaborator

Nice one!
I updated this in my fork too

@dotrung dotrung mentioned this issue Oct 19, 2017
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