-
Notifications
You must be signed in to change notification settings - Fork 8
Switched to AsyncKeyedLock #49
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
Open
MarkCiliaVincenti
wants to merge
1
commit into
dark-loop:master
Choose a base branch
from
MarkCiliaVincenti:AsyncKeyedLock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Is there a way to named lockers? If someone using this package also references your package for their own purposes and add the locker to the services, it would be replacing this configuration.
KeyedMonitor is internal and there won't be clashes.
Can you look into instrumenting the locker where you have a single constructor and initializing it using the options pattern.
and intrument it like
the second one allows for automatic injection when used as constructor parameters for
TService
and services provides a unique instance for this service, so it becomes a singleton for the service instead of a singleton for the application.The way it is right now does not ensure that external code will not change the service as this package requires it.
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.
Not sure if I understand you correctly. You're creating an instance of AsyncKeyedLocker and someone in a different assembly might also do the same, but every instance of AsyncKeyedLocker will have its own dictionary.
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.
Imagine we were just talking about a normal Dictionary here which you'd inject as a singleton. Unless you intentionally expose it no one will be able to modify your dictionary.
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.
Internally within this package we call
AddSingleton(new AsyncKeyedLocker<string>(options => ...))
. This gets invoked onAddFunctionsAuthentication(... )
The problem is when a consumer of this package has
It does not ensure the locker behavior for what this package needs will be kept intact if a user uses DarkLoop package and your package for any other purpose.
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.
No it shouldn't. It should be easy to test. I mean technically you could wrap the locker in an internal KeyedLock class but that's not going to change anything except for slightly reducing performance.
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.
As in the second AddSingleton will create a new instance not reuse an instance created by a different library. You can debug AsyncKeyedLocker so with that code you showed me you can see that it should go into the AsyncKeyedLock constructor twice, once for your library and once for wherever the library is used. That is you don't even need to set up locks or anything in order to test this.
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.
That's how
ServiceCollection
works. The last registered descriptor for a specific Type will be the one resolving that type. It does not depend on your code. This is why I'm asking if your component can add the functionality to ensure that.At the moment,
KeyedMonitor
ensures the desired behavior for the component.Hopefully you are able to add this functionality at some point to onboard this change.
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.
Create a wrapper class for it if you're worried? What you're asking for is extremely unoptimal and you can already do it yourself by creating a Dictionary<string, AsyncKeyedLocker> but I'd advise to avoid that. Sorry for my tone, very very long day at work.