Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add singleton factories to create instance per hub in management SDK #1070
Add singleton factories to create instance per hub in management SDK #1070
Changes from 9 commits
af2b77f
fe5b720
6800389
3a398b8
83a5239
97f7b99
9b7a85f
c1ba392
ef7969b
8dcb10c
0ca3c7a
58c578c
26dd841
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we let users decide if they
AddLogging
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about replace
AddLogging()
withservices.TryAdd(ServiceDescriptor.Singleton<ILoggerFactory, LoggerFactory>());
to make sure we have a default impl ofILoggerFctory
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can follow the general practice for a library package, for example, does SignalR pakage add default logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SignalR package doesn't addLogger. But since we already use ILoggerFactory, why we don't add default logger for user? If no default loggerFactory is set, program throws error when users don't specify logger. User can add their own loggerFactory and the default one won't take effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the service collection is for each hub? isn't it enough for each service manager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
IHubContext<Hub>
is for each hub, and oneServiceManager
could have multipleHubContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I am also confused here, why DI ctor not working ?
public ServiceHubContextFactory(ServiceHubLifetimeManagerFactory managerFactory, IHubContext<Hub> context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For two reasons:
IHubContext<Hub>
is not singleton. And its implHubContext<>
is an internal class, so we can't doservices.AddTransient(typeof(IHubContext<>),typeof(HubContext<>));
.HubContext<Hub>
depends onHubLiftTimeManager<>
, which depends on hub name in our impl.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is a factory for creating ServiceHubLifetimeManager, but it also start connection manager here. start should be called in other place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking,
CreateServiceHubContext()
is a method for creatingServiceHubContext
, but we start connection manager inside it, and this is unavoidable. Given this, I don't think starting connection manager in another factory is unacceptable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving the preparison for connection manager into WebSocketsHubLifetimeManager? So that WebSocketsHubLifetimeManager is no knowledge of hub name, and is also able to put into service collection, and make it transient? And set the connection container and start the container in ServiceHubContextFactory.CreateAsync like the old version? @vicancy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly,
WebSocketsHubLifetimeManager
is transient means thatIServiceHubContext
is transient too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you plan to get a new one for each request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key is that
HubContext<>
is an internal class, and we can't add it as transient.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you already put most of the class as a service into service collection, why not put WebSocketsHubLifetimeManager and RestHubLifetimeManager into service collection as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WebSocketsHubLifetimeManager
andRestHubLifetimeManager
are not singletons, they are for hub. And we don't know the hub name untilCreateServiceHubContext(...)
is called, while hub name is bound toServiceHubLifetimeManager
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinks it's better prepare all the thing before actually start the container, so put the startAsync to
ServiceHubContextFactory.CreateAsync
is betterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the actual difference between starting connection manager in
ServiceHubLifetimeManagerFactory
andServiceHubContextFactory
? NowServiceHubContextFactory
doesn't need to know the actual impl ofIServiceHubLifetimeManager
. I think to putconnectionManager.StartAsync()
inServiceHubContextFactory
breaks the hierarchy of the code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I mean is to put the used classes into service collections if possible, when everything is ready, start the connections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not singleton and we can't create connectionManager until we know hub name?