Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Consider using TryAddSingleton for services that users can override #2432

Closed
BrennanConroy opened this issue Jun 5, 2018 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@BrennanConroy
Copy link
Member

For our public services like IUserIdProvider,IHubActivator, HubLifetimeManager, and IHubProtocolResolver we should be using TryAddSingleton so that if a user adds the service before calling AddSignalR we don't override their setting.

services.AddSingleton(typeof(HubLifetimeManager<>), typeof(DefaultHubLifetimeManager<>));
services.AddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver));
services.AddSingleton(typeof(IHubContext<>), typeof(HubContext<>));
services.AddSingleton(typeof(IHubContext<,>), typeof(HubContext<,>));
services.AddSingleton(typeof(HubConnectionHandler<>), typeof(HubConnectionHandler<>));
services.AddSingleton(typeof(IUserIdProvider), typeof(DefaultUserIdProvider));
services.AddSingleton(typeof(HubDispatcher<>), typeof(DefaultHubDispatcher<>));
services.AddScoped(typeof(IHubActivator<>), typeof(DefaultHubActivator<>));

@davidfowl Did we have a reason for using AddSingleton or did we just forget?

Technically this would be a breaking change, but in a good, probably acceptable, way.

@davidfowl
Copy link
Member

We forgot, seems like a fine thing to change in 2.2. I'm not sure we need to patch it but we can if there's evidence that people are seeing problems.

@mikaelm12
Copy link
Contributor

Done: e41764c

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

No branches or pull requests

3 participants