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

Add Task Local Inject Setup behind new option #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jrosen081
Copy link
Contributor

@jrosen081 jrosen081 commented Oct 18, 2024

Closes #19

Adds a way to inject values locally without locking. This allows us to do local injecting within local injecting since it will merge the two setups. All local injecting makes a copy of the currently injecting service dictionary, which allows us to have the class be sendable, since we never mutate the same underlying object.

@@ -1,4 +1,5 @@
import Foundation

public final class Container {
private let localDependencyGraph: ThreadSafeDependencyGraph
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove it if we are certain we want task local to be the final way (then we can even remove the options in total or make it empty for now)



public func copy() -> Self {
return Self(valuesByType: self.valuesByType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want to create a new instance of the dictionary here which takes the values in, otherwise we have the same reference to a dict under the hood which could have issues with races I think (since this is a class not a struct)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are passing the dictionary into a new class, we should have a copy. Technically copy on write will make it the same instance, but it should be fine since those updates are atomic. What would be dangerous would be passing the ServiceDictionary itself, since that has a pointer to the actual same dictionary in multiple places and is definitely not sendable

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

Successfully merging this pull request may close these issues.

Add Experimental WhoopDI Task Local Injecting
2 participants