Skip to content

Can Factories capturing self cause circular references to occur on containers? #70

Answered by hmlongco
rsaccone asked this question in Q&A
Discussion options

You must be logged in to vote

It's not a worry. I may need to document this more, but as mentioned in the readme Factories are transient; created when needed, used, and then quickly discarded.

The definition of recommendationsCoordinator is a computed value. Hence its reference to self doesn't really exist until it's actually called. In a similar vein, that reference to the container in { RecommendationsCoordinator(storage: self.storage()) } isn't captured until the Factory for recommendationsCoordinator is created and returned.

If that Factory is evaluated (Container.shared.recommnedationsCoordinator()), then the closure will be called, the parameter self.storage() will be evaluated,.and the process starts over, recu…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@rsaccone
Comment options

@hmlongco
Comment options

Answer selected by hmlongco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants